Created
March 24, 2017 11:27
-
-
Save ViktorStiskala/cd7e64f9f1a0a0cad6d00db3b0865367 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
def validate_account_number(value): | |
checksum = sum(int(value[i]) * (8-i) for i in range(7)) % 11 | |
last_digit = int(value[-1]) | |
if checksum in [0, 10]: | |
c = 1 | |
elif checksum == 1: | |
c = 0 | |
else: | |
c = 11 - checksum | |
if last_digit != c: | |
raise ValidationError(self.message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment