Validate more than one input Field CPF

0

I have this Script for CPF validation. However in my form, there is more than one field that needs the validation of the CPF, inside a table that is added as it presses the add button. How do I get the script to validate these two other fields?

  

Script CPF Validation

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" >
  

E

<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, it is validating correctly.

The fields that also require validation are: cpfFilial and cpfContCustomer

When you click the "new" button on the table, it looks like this:

cpfFilial

asked by anonymous 02.05.2017 / 16:05

1 answer

0

I noticed you're using jQuery, I think you can do it this way:

$(document).on('blur keyup', "input[name^='cpf']",function() {
        $("#resposta").html(CPF.valida($(this).val()));
});

^ is a criterion selector starts with .

    
02.05.2017 / 16:20