Created
May 20, 2015 17:44
-
-
Save raspi/55c2b8d40b7e71ae43a6 to your computer and use it in GitHub Desktop.
This file contains 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
def is_vatnum(num): | |
if len(num) > 9: | |
return False | |
if "-" not in num: | |
return False | |
n,check = num.split("-") | |
try: | |
int(n) | |
except: | |
return False | |
try: | |
check = int(check) | |
except: | |
return False | |
multips = [7, 9, 10, 5, 8, 4, 2] | |
if len(n) != len(multips): | |
return False | |
control_sum = 0 | |
for idx, mnum in enumerate(multips): | |
nnum = int(n[idx]) | |
control_sum += nnum * mnum | |
control_sum %= 11 | |
if control_sum == 0: | |
return check == control_sum | |
elif control_sum >= 2 and control_sum <= 10: | |
return (11 - control_sum) == check | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment