Created
February 22, 2017 01:20
-
-
Save webarthur/a6ac0a713c67a37a9879303a2d252a84 to your computer and use it in GitHub Desktop.
Valida CNPJ - Função em JavaScript
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 is_cpf (c) { | |
if((c = c.replace(/[^\d]/g,"")).length != 11) | |
return false; | |
if (c == "00000000000") | |
return false; | |
var r; | |
var s = 0; | |
for (i=1; i<=9; i++) | |
s = s + parseInt(c[i-1]) * (11 - i); | |
r = (s * 10) % 11; | |
if ((r == 10) || (r == 11)) | |
r = 0; | |
if (r != parseInt(c[9])) | |
return false; | |
s = 0; | |
for (i = 1; i <= 10; i++) | |
s = s + parseInt(c[i-1]) * (12 - i); | |
r = (s * 10) % 11; | |
if ((r == 10) || (r == 11)) | |
r = 0; | |
if (r != parseInt(c[10])) | |
return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment