Пример #1
0
 def IBAN(obj, value):
     '''Checks that p_value corresponds to a valid IBAN number. IBAN stands
        for International Bank Account Number (ISO 13616). If the number is
        valid, the method returns True.'''
     if not value: return True
     # First, remove any non-digit or non-letter char
     v = ''
     for c in value:
         if alpha.match(c): v += c
     # Maximum size is 34 chars
     if (len(v) < 8) or (len(v) > 34): return False
     # 2 first chars must be a valid country code
     if not countries.exists(v[:2].upper()): return False
     # 2 next chars are a control code whose value must be between 0 and 96.
     try:
         code = int(v[2:4])
         if (code < 0) or (code > 96): return False
     except ValueError:
         return False
     # Perform the checksum
     vv = v[4:] + v[:4] # Put the 4 first chars at the end.
     nv = ''
     for c in vv:
         # Convert each letter into a number (A=10, B=11, etc)
         # Ascii code for a is 65, so A=10 if we perform "minus 55"
         if letter.match(c): nv += str(ord(c.upper()) - 55)
         else: nv += c
     return int(nv) % 97 == 1
Пример #2
0
 def IBAN(obj, value):
     '''Checks that p_value corresponds to a valid IBAN number. IBAN stands
        for International Bank Account Number (ISO 13616). If the number is
        valid, the method returns True.'''
     if not value: return True
     # First, remove any non-digit or non-letter char
     v = ''
     for c in value:
         if alpha.match(c): v += c
     # Maximum size is 34 chars
     if (len(v) < 8) or (len(v) > 34): return False
     # 2 first chars must be a valid country code
     if not countries.exists(v[:2].upper()): return False
     # 2 next chars are a control code whose value must be between 0 and 96.
     try:
         code = int(v[2:4])
         if (code < 0) or (code > 96): return False
     except ValueError:
         return False
     # Perform the checksum
     vv = v[4:] + v[:4]  # Put the 4 first chars at the end.
     nv = ''
     for c in vv:
         # Convert each letter into a number (A=10, B=11, etc)
         # Ascii code for a is 65, so A=10 if we perform "minus 55"
         if letter.match(c): nv += str(ord(c.upper()) - 55)
         else: nv += c
     return int(nv) % 97 == 1
Пример #3
0
 def BIC(obj, value):
     '''Checks that p_value corresponds to a valid BIC number. BIC stands
        for Bank Identifier Code (ISO 9362). If the number is valid, the
        method returns True.'''
     if not value: return True
     # BIC number must be 8 or 11 chars
     if len(value) not in (8, 11): return False
     # 4 first chars, representing bank name, must be letters
     for c in value[:4]:
         if not letter.match(c): return False
     # 2 next chars must be a valid country code
     if not countries.exists(value[4:6].upper()): return False
     # Last chars represent some location within a country (a city, a
     # province...). They can only be letters or figures.
     for c in value[6:]:
         if not alpha.match(c): return False
     return True
Пример #4
0
 def BIC(obj, value):
     '''Checks that p_value corresponds to a valid BIC number. BIC stands
        for Bank Identifier Code (ISO 9362). If the number is valid, the
        method returns True.'''
     if not value: return True
     # BIC number must be 8 or 11 chars
     if len(value) not in (8, 11): return False
     # 4 first chars, representing bank name, must be letters
     for c in value[:4]:
         if not letter.match(c): return False
     # 2 next chars must be a valid country code
     if not countries.exists(value[4:6].upper()): return False
     # Last chars represent some location within a country (a city, a
     # province...). They can only be letters or figures.
     for c in value[6:]:
         if not alpha.match(c): return False
     return True