Last active
August 29, 2015 14:17
-
-
Save fabian57/e6a23e83a2095b179031 to your computer and use it in GitHub Desktop.
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oui, c'est ça!