Skip to content

Instantly share code, notes, and snippets.

@cescoferraro
Created February 23, 2017 02:09
Show Gist options
  • Save cescoferraro/76929a8224b857429ed606e1704e2c35 to your computer and use it in GitHub Desktop.
Save cescoferraro/76929a8224b857429ed606e1704e2c35 to your computer and use it in GitHub Desktop.
testador de cpf.js
const TestaCPFFunction = (strCPF) => {
let Soma;
let Resto;
Soma = 0;
if (strCPF == "00000000000") {
return false
}
for (let i = 1; i <= 9; i++) {
Soma = Soma + parseInt(strCPF.substring(i - 1, i)) * (11 - i);
}
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) {
Resto = 0
}
if (Resto != parseInt(strCPF.substring(9, 10))) {
return false
}
Soma = 0;
for (let i = 1; i <= 10; i++) {
Soma = Soma + parseInt(strCPF.substring(i - 1, i)) * (12 - i);
}
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) {
Resto = 0
}
return Resto == parseInt(strCPF.substring(10, 11));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment