Created
May 4, 2010 17:18
-
-
Save rafacv/389684 to your computer and use it in GitHub Desktop.
Simple JS function to validate NIT/PIS/PASEP numbers
This file contains hidden or 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 ispis(pis) { | |
| pis = pis.toString(); | |
| var weight = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; | |
| var sum = 0, digito = 0; | |
| if (pis.length != 11 || pis.match(/\D/)) | |
| return false; | |
| pis = pis.split(""); | |
| for (var i=0; i < 10; i++) | |
| sum += weight[i] * pis[i]; | |
| digito = 11 - (sum % 11); | |
| digito = digito < 10 ? digito : 0; | |
| return pis[10] == digito; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment