Skip to content

Instantly share code, notes, and snippets.

@sistematico
Forked from joaohcrangel/validation-cpf.ts
Created August 31, 2020 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sistematico/888cddb7c727f589f136f2094446ea97 to your computer and use it in GitHub Desktop.
Save sistematico/888cddb7c727f589f136f2094446ea97 to your computer and use it in GitHub Desktop.
Função para validar CPF
function isValidCPF(number) {
var sum;
var rest;
sum = 0;
if (number == "00000000000") return false;
for (i=1; i<=9; i++) sum = sum + parseInt(number.substring(i-1, i)) * (11 - i);
rest = (sum * 10) % 11;
if ((rest == 10) || (rest == 11)) rest = 0;
if (rest != parseInt(number.substring(9, 10)) ) return false;
sum = 0;
for (i = 1; i <= 10; i++) sum = sum + parseInt(number.substring(i-1, i)) * (12 - i);
rest = (sum * 10) % 11;
if ((rest == 10) || (rest == 11)) rest = 0;
if (rest != parseInt(number.substring(10, 11) ) ) return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment