10 years ago
1
Topic
CPF Validation field
In Brazil we need to use the validation of CPF (registration of physical person), for the field in SEBLOD, this code is the function:
Javascript:
function validarCPF(cpf) {

cpf = cpf.replace(/[^\d]+/g,'');

if(cpf == '') return false;

// Elimina CPFs invalidos conhecidos
if (cpf.length != 11 ||
cpf == "00000000000" ||
cpf == "11111111111" ||
cpf == "22222222222" ||
cpf == "33333333333" ||
cpf == "44444444444" ||
cpf == "55555555555" ||
cpf == "66666666666" ||
cpf == "77777777777" ||
cpf == "88888888888" ||
cpf == "99999999999")
return false;

// Valida 1o digito
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;

// Valida 2o digito
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;

return true;

}









someone could get this plugin: http://www.seblod.com/v2/forum/Field-Validation-Rules-Plugin/29104-NEW-FIELD-Numeric-only-validation.html
and adapt the code above?

for testing:
Cpf valid:
437349187-90
878531744-62
343533884-95
674771748-13

Cpf invalid:
437349186-00
878531745-55
323533884-65
674771748-13
Get a VIP membership
10 years ago
0
Level 1
Hi Goiano,

Thank you for your post and welcome to SEBLOD forum.

I advise to use the "regeX" validation plugin. The use of this kind of plugin suppose you know "regular expression".

Regards,
Mehdi.

Get a Book for SEBLOD