-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIBANValidation.py
More file actions
37 lines (34 loc) · 1.38 KB
/
Copy pathIBANValidation.py
File metadata and controls
37 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# IBAN Validator
##step 1) Check that the total IBAN length is correct as per
##the country (this program won't do that, but you can modify
##the code to meet this requirement if you wish; note: you have
##to teach the code all the lengths used in Europe)
##(step 2) Move the four initial characters to the end of
##the string (i.e., the country code and the check digits)
##(step 3) Replace each letter in the string with two digits,
##thereby expanding the string, where A = 10, B = 11 ... Z = 35;
##(step 4) Interpret the string as a decimal integer and compute
##the remainder of that number on division by 97; If the remainder
##is 1, the check digit test is passed and the IBAN might be valid.
iban = input("Enter IBAN, please: ")
iban = iban.replace(' ','')
#lll6the entered IBAN must consist of digits and letters only - if it doesn't.
if not iban.isalnum():
print("You have entered invalid characters.")
elif len(iban) < 15:
print("IBAN entered is too short.")
elif len(iban) > 31:
print("IBAN entered is too long.")
else:
iban = (iban[4:] + iban[0:4]).upper()
iban2 = ''
for ch in iban:
if ch.isdigit():
iban2 += ch
else:
iban2 += str(10 + ord(ch) - ord('A'))
ibann = int(iban2)
if ibann % 97 == 1:
print("IBAN entered is valid.")
else:
print("IBAN entered is invalid.")