Skip to content

Instantly share code, notes, and snippets.

@BrunoDSouza
Forked from joaohcrangel/validation-cpf.ts
Created June 28, 2021 19:45
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 BrunoDSouza/542ab43cc3c18ed58d45c8932f9e7723 to your computer and use it in GitHub Desktop.
Save BrunoDSouza/542ab43cc3c18ed58d45c8932f9e7723 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