0
I have this script for CPF validation. But in my form, there is more than one field that requires CPF validation, within a table that adds as you press the add button. How should I make the script validate these other two fields ?
Script Validation CPF
function CPF(){"user_strict";function r(r){
for(
var t=null,n=0;9>n;++n)t+=r.toString().charAt(n)*(10-n);
var i=t%11;return i=2>i?0:11-i}
function t(r){
for(
var t=null,n=0;10>n;++n)t+=r.toString().charAt(n)*(11-n);var i=t%11;
return i=2>i?0:11-i}
var n="CPF Inválido",i="CPF Válido";this.gera=
function(){
for(
var n="",i=0;9>i;++i)n+=Math.floor(9*Math.random())+"";
var o=r(n),a=n+"-"+o+t(n+""+o);
return a},this.valida=
function(o){
for(
var a=o.replace(/\D/g,""),u=a.substring(0,9),f=a.substring(9,11),v=0;10>v;v++)
if(""+u+f==""+v+v+v+v+v+v+v+v+v+v+v)
return n;var c=r(u),e=t(u+""+c);
return f.toString()===c.toString()+e.toString()?i:n}}
var CPF = new CPF();
for(var i =0;i<40;i++) {
var temp_cpf = CPF.gera();
//document.write(temp_cpf+" = "+CPF.valida(temp_cpf)+"<br>");
}
$("#input").keypress(function(){
$("#resposta").html(CPF.valida($(this).val()));
});
$("#input").blur(function(){
$("#resposta").html(CPF.valida($(this).val()));
});
Field within the Table
<td><input class="form-control" style="width: 180px" type="text" id="cpfFilial" name="cpfFilial" mask="000.000.000-00" >
And
<td><input class="form-control" type="text" style="width: 100%;" id="cpfContCliente" name="cpfContCliente" mask="000.000.000-00"></td>
The first CPF field that is outside tables, is just a normal input, this validating correctly.
The fields that also need validation are: cpfFilial and cpfContCliente
When you press the "new" button on the table, they look like this :
cpfFilial___1 / cpfFilial___2 / cpfContCliente___1 / cpfContCliente___2
It seems to me that the code you posted is incomplete. That’s the complete code?
– Lucas Torres
The Script? is complete yes !
– Karina Pinheiro