javascript - how to alert if the cuit is valid or not? -
i have input id cuit , need validate input in argentina. found code want run alert or know if cuit valid or not.
how can this?
function validacuit(scuit) { var amult = '5432765432'; var amult = amult.split(''); if (scuit && scuit.length == 11) { acuit = scuit.split(''); var iresult = 0; (i = 0; <= 9; i++) { iresult += acuit[i] * amult[i]; } iresult = (iresult % 11); iresult = 11 - iresult; if (iresult == 11) iresult = 0; if (iresult == 10) iresult = 9; if (iresult == acuit[10]) { return true; } } return false; }
if dont true/false output ternary (?) operator friend:
alert( validacuit( "1234" ) ? "valid input!" : "wrong input!");
Comments
Post a Comment