Validador Javascript

Home Forums Quform WordPress Validador Javascript

This topic is: not resolved
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #30296
    guver
    Participant

    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

    #30302
    Ally
    Support Staff

    You 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
    #32300
    Appmobi
    Participant

    Hello 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?

    #32302
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #33202
    johnpaes
    Participant

    Hello, 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.

    #33206
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #33207
    johnpaes
    Participant

    Hello 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.

    #33209
    johnpaes
    Participant

    Hello Ally,
    Do you think this can work? Can i have hope?

    Thank you very much.
    Best Regards,
    John.

    #33210
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #33211
    johnpaes
    Participant

    Hello 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.

    #33212
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy