Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2014 04:02
Show Gist options
  • Select an option

  • Save anonymous/7aa8dc808082c95ffc97 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/7aa8dc808082c95ffc97 to your computer and use it in GitHub Desktop.
def is_valid_singapore_nric_number(number):
number = number.upper()
prefix = 0 if number[0] in "SF" else 4
table = "JZIHGFEDCBA" if number[0] in "ST" else "XWUTRQPNMLK"
check = (prefix + sum([int(number[i + 1]) * int(a)
for i, a in enumerate("2765432")])) % 11
return table[check] == number[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment