Skip to content

Instantly share code, notes, and snippets.

@fabian57
Last active August 29, 2015 14:17
Show Gist options
  • Save fabian57/e6a23e83a2095b179031 to your computer and use it in GitHub Desktop.
Save fabian57/e6a23e83a2095b179031 to your computer and use it in GitHub Desktop.
VALID_LENGTHS = dict()
for s in open("is_valid_iban_data.txt").read().split("\n"):
VALID_LENGTHS[s[:2]] = int(s[3:])
def is_valid_iban(string):
iban = string.replace(" ", "").replace("-", "").upper()
if len(iban) == VALID_LENGTHS[iban[:2]]:
inverted_iban = iban[4:] + iban[:4]
number = ""
for c in inverted_iban:
if "A" <= c <= "Z":
number += str(ord(c)-55)
elif c in "0123456789":
number += c
else:
return False
return int(number) % 97 == 1
@laowantong
Copy link

Oui, c'est ça!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment