def validate(number): """Check if the number provided is a valid Montenegro IBAN.""" number = iban.validate(number, check_country=False) if not number.startswith('ME'): raise InvalidComponent() if _checksum(number[4:]) != 1: raise InvalidChecksum() return number
def _format_iban(self, cr, uid, acc_number): ''' This function removes all characters from given 'string' that isn't a alpha numeric and converts it to upper case, checks checksums and groups by 4 ''' res = '' if acc_number: _logger = logging.getLogger(__name__) _logger.dbug('FGF acc_number %s' % (acc_number)) try: a = iban.validate(acc_number) except: raise osv.except_osv(_('Error!'), (_('%s is not a valid IBAN.') % (acc_number))) res = iban.format(a) return res
def valida_iban(iban_no): from stdnum import iban try: return iban.validate(iban_no) except: raise ValidationError("IBAN non valido.")
def validate(number): """Check if the number provided is a valid Norwegian IBAN.""" number = iban.validate(number, check_country=False) kontonr.validate(to_kontonr(number)) return number
def validate(number): """Check if the number provided is a valid Spanish IBAN.""" number = iban.validate(number, check_country=False) ccc.validate(to_ccc(number)) return number
def __init__(self, account=None, creditor=None, final_creditor=None, amount=None, currency='CHF', due_date=None, debtor=None, ref_number=None, extra_infos='', language='en', top_line=True): # Account (IBAN) validation if not account: raise ValueError("The account parameter is mandatory") if not iban.is_valid(account): raise ValueError("Sorry, the IBAN is not valid") self.account = iban.validate(account) if self.account[:2] not in IBAN_ALLOWED_COUNTRIES: raise ValueError("IBAN must start with: %s" % ", ".join(IBAN_ALLOWED_COUNTRIES)) iban_iid = int(self.account[4:9]) if QR_IID["start"] <= iban_iid <= QR_IID["end"]: self.account_is_qriban = True else: self.account_is_qriban = False if amount is not None: if isinstance(amount, Decimal): amount = str(amount) elif not isinstance(amount, str): raise ValueError( "Amount can only be specified as str or Decimal.") # remove commonly used thousands separators amount = amount.replace("'", "").strip() # people often don't add .00 for amounts without cents/rappen if "." not in amount: amount = amount + ".00" # support lazy people who write 12.1 instead of 12.10 if amount[-2] == '.': amount = amount + '0' # strip leading zeros amount = amount.lstrip("0") # some people tend to strip the leading zero on amounts below 1 CHF/EUR # and with removing leading zeros, we would have removed the zero before # the decimal delimiter anyway if amount[0] == ".": amount = "0" + amount m = re.match(AMOUNT_REGEX, amount) if not m: raise ValueError( "If provided, the amount must match the pattern '###.##'" " and cannot be larger than 999'999'999.99") self.amount = amount if currency not in self.allowed_currencies: raise ValueError("Currency can only contain: %s" % ", ".join(self.allowed_currencies)) self.currency = currency if due_date: m = re.match(DATE_REGEX, due_date) if not m: raise ValueError( "The date must match the pattern 'YYYY-MM-DD'") due_date = date(*[int(g) for g in m.groups()]) self.due_date = due_date if not creditor: raise ValueError("Creditor information is mandatory") try: self.creditor = Address.create(**creditor) except ValueError as err: raise ValueError("The creditor address is invalid: %s" % err) if final_creditor is not None: # The standard says ultimate creditor is reserved for future use. # The online validator does not properly validate QR-codes where # this is set, saying it must not (yet) be used. raise ValueError( "final creditor is reserved for future use, must not be used") else: self.final_creditor = final_creditor if debtor is not None: try: self.debtor = Address.create(**debtor) except ValueError as err: raise ValueError("The debtor address is invalid: %s" % err) else: self.debtor = debtor if not ref_number: self.ref_type = 'NON' self.ref_number = None elif ref_number.strip()[:2].upper() == "RF": if iso11649.is_valid(ref_number): self.ref_type = 'SCOR' self.ref_number = iso11649.validate(ref_number) else: raise ValueError("The reference number is invalid") elif esr.is_valid(ref_number): self.ref_type = 'QRR' self.ref_number = esr.format(ref_number).replace(" ", "") else: raise ValueError("The reference number is invalid") # A QRR reference number must only be used with a QR-IBAN and # with a QR-IBAN, a QRR reference number must be used if self.account_is_qriban: if self.ref_type != 'QRR': raise ValueError("A QR-IBAN requires a QRR reference number") else: if self.ref_type == 'QRR': raise ValueError( "A QRR reference number is only allowed for a QR-IBAN") if extra_infos and len(extra_infos) > 140: raise ValueError( "Additional information cannot contain more than 140 characters" ) self.extra_infos = extra_infos if language not in ['en', 'de', 'fr', 'it']: raise ValueError("Language should be 'en', 'de', 'fr', or 'it'") self.language = language self.top_line = top_line
def validate(self, text, **kwargs): text = sanitize_text(text) try: return iban.validate(text) except ValidationError: return False
def validate_IBAN(iban_param): try: iban.validate(iban_param) except Exception: raise ValidationError('Potrebno je unijeti ispravan IBAN')
def validate(self, value: str) -> bool: text = sanitize_text(value) try: return cast(bool, iban.validate(text)) except ValidationError: return False
def validate(number): """Checks to see if the number provided is a valid Spanish IBAN.""" number = iban.validate(number, check_country=False) ccc.validate(to_ccc(number)) return number