Created
July 16, 2018 14:06
-
-
Save diogoalexsmachado/581d6aab90acb2164a072bfd215d5534 to your computer and use it in GitHub Desktop.
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 validarNISS() { | |
var niss = $("#inputNISS").val(); | |
//deve ter 11 dígitos | |
if(niss.length != 11) { | |
swal("Aviso", "O número de Segurança Social deverá ter 11 dígitos.", "warning"); | |
} else { | |
var FACTORS = [29, 23, 19, 17, 13, 11, 7, 5, 3, 2]; | |
var nissArray = []; | |
for (var i = 0; i < niss.length; i++) { | |
nissArray[i] = niss.charAt(i); | |
} | |
var sum=0; | |
//faz a soma do digito [j] x o dígito [j] do array dos fatores | |
for (var j = 0; j < FACTORS.length; j++) { | |
sum += nissArray[j] * FACTORS[j]; | |
} | |
//verifica se dá resto 0 | |
if (nissArray[nissArray.length - 1] == (9 - (sum % 10))) { | |
msgsucesso_valido() | |
} else { | |
swal("Aviso", "O número de Segurança Social não é valido.", "warning"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment