Created
March 7, 2012 09:34
-
-
Save biermeester/1992197 to your computer and use it in GitHub Desktop.
Determine if the given parameter is a valid (Dutch) social security number, known as Burger Service Nummer.
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
def is_eleven_proof(bsn): | |
""" Determine if the given parameter is a valid (Dutch) social security | |
number, known as Burger Service Nummer. | |
The parameter may be an integer or a string. Non-digit characters will | |
be filtered out. | |
The function returns 'True' if the number is valid and 'False' | |
otherwise. | |
""" | |
if isinstance(bsn, (str, unicode)): | |
bsn = "".join(n for n in bsn if n.isdigit()) | |
elif isinstance(bsn, int): | |
bsn = str(bsn) | |
else: | |
return False | |
weights = [-1, 2, 3, 4, 5, 6, 7, 8, 9] | |
if len(bsn) not in (8,9): | |
return False | |
accum = 0 | |
for i, n in enumerate(bsn[::-1]): | |
accum += weights[i] * int(n) | |
if accum % 11: | |
return False | |
else: | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment