# Validate Field

Home Forums Quform WordPress Validate Field

This topic is: resolved
Viewing 15 posts - 1 through 15 (of 15 total)
• Author
Posts
• #29685

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) -> bool var v: int`

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

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

` //Note: True if the check digits are as expected. return v = cnpj and v = cnpj`

how can i implement this?

#29686

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

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

#29697

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

#29708

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

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

#29716

#29717

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

#29724

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

#29728

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

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

I resolved, I used ` tofixed `, thanks, Ally

#29739