Created
August 3, 2012 21:54
-
-
Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.
Validate NIP
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
/* | |
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