-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (39 loc) · 1.32 KB
/
Copy pathscript.js
File metadata and controls
53 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
console.log('SERASA');
function validaCPF(cpf){
if(cpf.length !=11) {
return false;
} else {
var numeros = cpf.substring(0, 9);
var digitos = cpf.substring(9);
var soma = 0;
for (var i = 10; i > 1; i--) {
soma += numeros.charAt(10 -i) * i;
}
console.log(soma);
var resultado = (soma % 11) < 2 ? 0 : 11 - (soma % 11);
if (resultado != digitos.charAt(0)) {
return false;
}
soma = 0;
numeros = cpf.substring(0, 10);
for (var k = 11; k > 1; k--){
soma += numeros.charAt(11 - k) * k;
}
resultado = (soma % 11) < 2 ? 0 : 11 - (soma % 11);
if (resultado != digitos.charAt(1)) {
return false;
}
return true;
}
}
function validacao() {
console.log('Iniciando validação CPF');
document.getElementById('success').style.display = 'none';
document.getElementById('error').style.display = 'none';
var cpf = document.getElementById('cpf_digitado').value;
var resultadoValidacao = validaCPF(cpf);
if(resultadoValidacao == true) {
document.getElementById('success').style.display = 'block';
} else { document.getElementById('error').style.display = 'block';
}
}