Created
May 29, 2020 23:04
-
-
Save jj-marinho/b7ebb86f27a598e3e8bafe7202e436fb to your computer and use it in GitHub Desktop.
Validando 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 TestaCPF(strCPF) { | |
var Soma; | |
var Resto; | |
Soma = 0; | |
if (strCPF == "00000000000") return false; | |
for (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 (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; | |
if (Resto != parseInt(strCPF.substring(10, 11) ) ) return false; | |
return true; | |
} | |
// https://www.devmedia.com.br/validar-cpf-com-javascript/23916 veio daqui |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment