Created
April 26, 2016 12:36
-
-
Save pierstitus/59ab321137877345872a6245a7f2ea4a 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
| import re | |
| import string | |
| def iban_cepa_check(nr): | |
| """ Check if given IBAN/CETA account number is valid. """ | |
| nr = nr.replace(' ', '') | |
| if re.fullmatch('[A-Z]{2}\d{2}[A-Z]{4}\d{10}', nr): | |
| check_org = int(nr[2:4]) | |
| nr = nr[4:] + nr[:2] | |
| else: | |
| raise Exception("Invalid format, needs to be like 'NL05 RABO 1234 1234 00' (with or without spaces)") | |
| check = 98 - int(''.join(n if n.isdigit() else str(string.ascii_uppercase.index(n) + 10) for n in nr)) * 100 % 97 | |
| if check_org != check: | |
| print('invalid, check value should be %d.' % check) | |
| else: | |
| print('valid') | |
| return check | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment