Skip to content

iban

validators.iban.iban(value)

Return whether or not given value is a valid IBAN code.

Examples:

>>> iban('DE29100500001061045672')
# Output: True
>>> iban('123456')
# Output: ValidationError(func=iban, ...)

Parameters:

Name Type Description Default
value str

IBAN string to validate.

required

Returns:

Type Description
Literal[True]

If value is a valid IBAN code.

ValidationError

If value is an invalid IBAN code.

Source code in src/validators/iban.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@validator
def iban(value: str, /):
    """Return whether or not given value is a valid IBAN code.

    Examples:
        >>> iban('DE29100500001061045672')
        # Output: True
        >>> iban('123456')
        # Output: ValidationError(func=iban, ...)

    Args:
        value:
            IBAN string to validate.

    Returns:
        (Literal[True]): If `value` is a valid IBAN code.
        (ValidationError): If `value` is an invalid IBAN code.
    """
    return (
        (re.match(r"^[a-z]{2}[0-9]{2}[a-z0-9]{11,30}$", value, re.IGNORECASE) and _mod_check(value))
        if value
        else False
    )