Skip to content

Instantly share code, notes, and snippets.

@OpenGrid
Created August 3, 2012 21:54
Show Gist options
  • Select an option

  • Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.

Select an option

Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.
Validate NIP
/*
Check for validity of polish VAT ID number: NIP
*/
function isNIPvalid(NIP) {
var controlSum = 0, factors = [6, 5, 7, 2, 3, 4, 5, 6, 7];
NIP += '';
NIP = NIP.replace(/[^0-9]+/g,'');
if(NIP.length < 10 || NIP.length > 10)
return false;
for(var c = 0; c <= 8; c++) {
controlSum += parseInt(NIP.charAt(c)) * factors[c];
}
if(controlSum % 11 == parseInt(NIP.charAt(9))) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment