1var CustomValidation = {}; 2CustomValidation.Init = function () { 3 //CustomValidationCPF 4 $.validator.addMethod('customvalidationcpf', function (value, element, params) { 5 var cpf = value.replace(/[^0-9]/gi, ''); //Remove tudo que não for número 6 if (value.length == 0) 7 return true; //vazio 8 if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") 9 return false; 10 add = 0; 11 for (i = 0; i < 9; i++) 12 add += parseInt(cpf.charAt(i)) * (10 - i); 13 rev = 11 - (add % 11); 14 if (rev == 10 || rev == 11) 15 rev = 0; 16 if (rev != parseInt(cpf.charAt(9))) 17 return false; 18 add = 0; 19 for (i = 0; i < 10; i++) 20 add += parseInt(cpf.charAt(i)) * (11 - i); 21 rev = 11 - (add % 11); 22 if (rev == 10 || rev == 11) 23 rev = 0; 24 if (rev != parseInt(cpf.charAt(10))) 25 return false; 26 return true; //cpf válido 27 }, ''); 28 $.validator.unobtrusive.adapters.add('customvalidationcpf', {}, function (options) { 29 options.rules['customvalidationcpf'] = true; 30 options.messages['customvalidationcpf'] = options.message; 31 }); 32} 33//executa -- importante que isso seja feito antes do document.ready 34CustomValidation.Init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.