Skip to content

Instantly share code, notes, and snippets.

@OpenGrid
Created August 3, 2012 21:54
Show Gist options
  • Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.
Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.
Validate NIP
/*
Check for validity of polish VAT ID number: NIP
*/
function NIPIsValid(nip) {
var weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
nip = nip.replace(/[\s-]/g, '');
if (nip.length == 10 && parseInt(nip, 10) > 0) {
var sum = 0;
for(var i = 0; i < 9; i++){
sum += nip[i] * weights[i];
}
return (sum % 11) == nip[9];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment