Home › Forums › Quform WordPress › Validador Javascript
- This topic has 10 replies, 3 voices, and was last updated 3 years, 4 months ago by Ally.
- AuthorPosts
- November 25, 2019 at 8:27 pm #30296guverParticipant
Hello friends,
How are you? I need your help creating a Javascript validation field on my form.
I would like to create a specified validation for the 11 digit numbering of a Brazilian document called CPF.
Is there any way to add Javascript to perform validation?
My form link: http://cadastro.sensorh.com.br/
Thank you for your attention!
Guver
November 26, 2019 at 11:39 am #30302AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- This reply was modified 3 years, 11 months ago by Ally. Reason: Fixed issue with the code displaying the validation error after submtting the form
December 1, 2020 at 5:06 pm #32300AppmobiParticipantHello good afternoon.
Thank you it helped me a lot.
But even if the CPF number is correct, it returns the error message at the end.
He accepts, all right, but in the end when the confirmation message of the form goes, so does the CPF error message, even though it is right and already accepted in the DB.
Can you help me?
December 2, 2020 at 10:57 am #32302AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 15, 2021 at 5:32 pm #33202johnpaesParticipantHello, could you help me to use this “Validator” on Custom JavaScript field?
<script language=”javascript”>
function VerificaCPF () {
if (vercpf(document.frmcpf.cpf.value))
{document.frmcpf.submit();}else
{errors=”1″;if (errors) alert(‘CPF NÃO VÁLIDO’);
document.retorno = (errors == ”);}}
function vercpf (cpf)
{if (cpf.length != 11 || cpf == “000.00.0000-00” || cpf == “111.111.111-11” || cpf == “222.222.222-22” || cpf == “333.333.333-33” || cpf == “444.444.444-44” || cpf == “555.555.555-55” || cpf == “666.666.666-66” || cpf == “777.777.777-77” || cpf == “888.888.888-88” || cpf == “999.999.999-99”)
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 – i);
rev = 11 – (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 – i);
rev = 11 – (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;Thank you very much!
Best Regards,
John.July 16, 2021 at 11:13 am #33206AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 16, 2021 at 2:19 pm #33207johnpaesParticipantHello Ally,
Thank you very much for your quick reply.
Sorry, part of the code was missing. I also didn’t comment that in this same field have an active mask working with this code:jQuery(function ($) {
if ($.fn.mask) {
$(‘.quform-field-1_6’).mask(‘000.000.000-00’);
}
});This mask works perfectly.
Here we have the complete “validator” code.
———–function validarCPF(cpf) {
cpf = cpf.replace(/[^\d]+/g,”);
if(cpf == ”) return false;
if (cpf.length != 11 ||
cpf == “000.000.000-00” ||
cpf == “111.111.111-11” ||
cpf == “222.222.222-22” ||
cpf == “333.333.333-33” ||
cpf == “444.444.444-44” ||
cpf == “555.555.555-55” ||
cpf == “666.666.666-66” ||
cpf == “777.777.777-77” ||
cpf == “888.888.888-88” ||
cpf == “999.999.999-99”)
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 – i);
rev = 11 – (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 – i);
rev = 11 – (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;
return true;
}—————————–
Thank you very much.
Best Regards,
John.July 19, 2021 at 11:32 pm #33209johnpaesParticipantHello Ally,
Do you think this can work? Can i have hope?Thank you very much.
Best Regards,
John.July 20, 2021 at 10:11 am #33210AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 21, 2021 at 12:13 am #33211johnpaesParticipantHello Ally,
I managed to set the validator following your instructions. The problem is that I can send the form even getting the error message in this field. Is it possible to fix it?Thank you very much!
Best Regards,
John.July 21, 2021 at 9:41 am #33212AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.