Home › Forums › Quform WordPress › Validate Field
- This topic has 14 replies, 2 voices, and was last updated 4 years, 8 months ago by Ally.
- AuthorPosts
- July 26, 2019 at 9:02 pm #29685sistemaParticipant
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?
July 26, 2019 at 10:03 pm #29686sistemaParticipantAnd i need to validate a money field.
So I need to allow a $ cash sign and decimal. Is there anyway to do this correctly?July 30, 2019 at 2:14 am #29695sistemaParticipantit is possible to auto fill in the sign and decimals?
July 30, 2019 at 4:05 am #29697sistemaParticipantexemple for decimal and sign, https://pinoyfirst.com.au/en/index.html
July 31, 2019 at 7:34 am #29708sistemaParticipantHello 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});
}
});
July 31, 2019 at 9:35 am #29709sistemaParticipantHi Ally, I was able to validate cnpj, now I just need to correct the calculation with dot, and comma.
July 31, 2019 at 10:57 am #29716AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 31, 2019 at 11:14 am #29717sistemaParticipantThanks 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?July 31, 2019 at 11:44 am #29723AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 31, 2019 at 11:58 am #29724sistemaParticipantHi, 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.
July 31, 2019 at 12:07 pm #29726AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 31, 2019 at 12:20 pm #29728sistemaParticipantdid not work.
Two things happened.in some values, the result was totally different:
10,00 + 10,01 = 20.009,999,999,999,998in some other values it worked.
and in other values it was the same
100,10 + 100,10 = 200.2the correct would be 200,00
sorry is filling you with questions
July 31, 2019 at 12:42 pm #29730sistemaParticipantI 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
August 1, 2019 at 1:02 am #29735sistemaParticipantI resolved, I used
tofixed
, thanks, AllyAugust 1, 2019 at 11:29 am #29739AllySupport 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.