Validate Field

Home Forums Quform WordPress Validate Field

This topic is: resolved

This topic contains 14 replies, has 2 voices, and was last updated by  Ally 2 months, 3 weeks ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #29685

    sistema
    Participant

    I need to validate a 14 digit number field, a calculation is made

    Example: XX.XXX.XXX/YYYY-ZZ

    code below:

    function ValidateCNPJ(cnpj: int[14]) -> bool
    var v: int[2]

    //Note: Calculates the first check digit.
    v[1] := 5×cnpj[1] + 4×cnpj[2] + 3×cnpj[3] + 2×cnpj[4]
    v[1] += 9×cnpj[5] + 8×cnpj[6] + 7×cnpj[7] + 6×cnpj[8]
    v[1] += 5×cnpj[9] + 4×cnpj[10] + 3×cnpj[11] + 2×cnpj[12]
    v[1] := 11 - v[1] mod 11
    v[1] := 0 if v[1] ≥ 10

    //Note: Calculates the second check digit.
    v[2] := 6×cnpj[1] + 5×cnpj[2] + 4×cnpj[3] + 3×cnpj[4]
    v[2] += 2×cnpj[5] + 9×cnpj[6] + 8×cnpj[7] + 7×cnpj[8]
    v[2] += 6×cnpj[9] + 5×cnpj[10] + 4×cnpj[11] + 3×cnpj[12]
    v[2] += 2×cnpj[13]
    v[2] := 11 - v[2] mod 11
    v[2] := 0 if v[2] ≥ 10

    //Note: True if the check digits are as expected.
    return v[1] = cnpj[13] and v[2] = cnpj[14]

    how can i implement this?

    #29686

    sistema
    Participant

    And i need to validate a money field.
    So I need to allow a $ cash sign and decimal. Is there anyway to do this correctly?

    #29695

    sistema
    Participant

    it is possible to auto fill in the sign and decimals?

    #29697

    sistema
    Participant

    exemple for decimal and sign, https://pinoyfirst.com.au/en/index.html

    #29708

    sistema
    Participant

    Hello ally, I used the code below to make the calculation, but the calculation ignores the point, and the comma.
    how can i fix this?


    jQuery(function ($) {
    var calculate = function () {
    var total = 0;

    var val4 = $('.quform-field-5_3').val();
    var val5 = $('.quform-field-5_4').val();

    if (val4 && val4.length && val5 && val5.length ) {
    total += parseFloat(val4);
    total += parseFloat(val5);
    }

    // Display the result to the user
    $('#form-total').text('Total: $' + total);

    // Set the value of the hidden field
    $('.quform-field-5_6').val('$' + total);
    };

    // Calculate on page load
    calculate();

    // Recalculate when these text input fields are changed
    $('.quform-field-5_3').on('keyup blur', calculate);
    $('.quform-field-5_4').on('keyup blur', calculate);
    });

    jQuery(function ($) {
    if ($.fn.mask) {
    $('.quform-field-5_3').mask('#.##0,00', {reverse: true});
    }
    });

    jQuery(function ($) {
    if ($.fn.mask) {
    $('.quform-field-5_4').mask('#.##0,00', {reverse: true});
    }
    });

    #29709

    sistema
    Participant

    Hi Ally, I was able to validate cnpj, now I just need to correct the calculation with dot, and comma.

    #29716

    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.

    #29717

    sistema
    Participant

    Thanks for answering me ally.

    I used the code and it worked, but value is being printed wrong.

    example:

    1.000,20 + 1.000,20 = 2000.4

    the correct one would be 2.000,40
    is it possible to fix this?

    #29723

    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.

    #29724

    sistema
    Participant

    Hi, I looked at the page. But the truth is that I know almost nothing about javascript or php. so I wouldn’t know how to fit these codes very well.

    #29726

    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.

    #29728

    sistema
    Participant

    did not work.
    Two things happened.

    in some values, the result was totally different:
    10,00 + 10,01 = 20.009,999,999,999,998

    in some other values it worked.

    and in other values it was the same
    100,10 + 100,10 = 200.2

    the correct would be 200,00

    sorry is filling you with questions

    #29730

    sistema
    Participant

    I was taking a look, and realized that the code is actually working, this value:

    10,00 + 10,01 = 20.009,999,999,999,998

    is correct, but he added many decimal places, the ideal would be:

    0,00 + 10,01 = 20,01

    #29735

    sistema
    Participant

    I resolved, I used tofixed , thanks, Ally

    #29739

    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 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.

Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy