Skip to content

pydantic_extra_types.routing_number

ABARoutingNumber

ABARoutingNumber(routing_number)

Bases: str

Source code in pydantic_extra_types/routing_number.py
12
13
14
def __init__(self, routing_number: str):
    self.validate_digits(routing_number)
    self._routing_number = self.validate_routing_number(routing_number)

validate_routing_number classmethod

validate_routing_number(routing_number)

Check digit algorithm for ABA routing transit number. https://en.wikipedia.org/wiki/ABA_routing_transit_number#Check_digit https://www.routingnumber.com/

Source code in pydantic_extra_types/routing_number.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@classmethod
def validate_routing_number(cls, routing_number: str) -> str:
    """
    Check digit algorithm for ABA routing transit number.
    https://en.wikipedia.org/wiki/ABA_routing_transit_number#Check_digit
    https://www.routingnumber.com/
    """
    checksum = (
        3 * (sum(map(int, [routing_number[0], routing_number[3], routing_number[6]])))
        + 7 * (sum(map(int, [routing_number[1], routing_number[4], routing_number[7]])))
        + sum(map(int, [routing_number[2], routing_number[5], routing_number[8]]))
    )
    if checksum % 10 != 0:
        raise PydanticCustomError('aba_routing_number', 'Incorrect ABA routing transit number')
    return routing_number