-
-
Save sistematico/888cddb7c727f589f136f2094446ea97 to your computer and use it in GitHub Desktop.
Função para validar CPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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