Skip to content

Instantly share code, notes, and snippets.

@rafacv
Created May 4, 2010 17:18
Show Gist options
  • Select an option

  • Save rafacv/389684 to your computer and use it in GitHub Desktop.

Select an option

Save rafacv/389684 to your computer and use it in GitHub Desktop.
Simple JS function to validate NIT/PIS/PASEP numbers
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