Created
June 10, 2011 12:44
-
-
Save barend/1018771 to your computer and use it in GitHub Desktop.
Burgerservicenummer Elfproef Validator
This file contains 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
/** Validate BSN according to http://nl.wikipedia.org/wiki/Burgerservicenummer */ | |
private boolean isValidBSN(int candidate) { | |
if (candidate <= 9999999 || candidate > 999999999) { | |
return false; | |
} | |
int sum = -1 * candidate % 10; | |
for (int multiplier = 2; candidate > 0; multiplier++) { | |
int val = (candidate /= 10) % 10; | |
sum += multiplier * val; | |
} | |
return sum != 0 && sum % 11 == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting that you started with 100000000, because the first years (everyone that transferred from the old system) these numbers had 8 digits. Those numbers got a leading zero when the length of the number was increased to 9 digits.