Skip to content

Instantly share code, notes, and snippets.

@biermeester
Created March 7, 2012 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biermeester/1992197 to your computer and use it in GitHub Desktop.
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.
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