Skip to content

Phone Numbers

The pydantic_extra_types.phone_numbers module provides the PhoneNumber data type.

This class depends on the [phonenumbers] package, which is a Python port of Google's [libphonenumber].

PhoneNumber

Bases: str

A wrapper around phonenumbers package, which is a Python port of Google's libphonenumber.

supported_regions instance-attribute class-attribute

supported_regions: list[str] = sorted(
    phonenumbers.SUPPORTED_REGIONS
)

The supported regions.

supported_formats instance-attribute class-attribute

supported_formats: list[str] = sorted(
    [
        f
        for f in phonenumbers.PhoneNumberFormat.__dict__.keys()
        if f.isupper()
    ]
)

The supported phone number formats.

default_region_code class-attribute

default_region_code: str | None = None

The default region code to use when parsing phone numbers without an international prefix.

phone_format instance-attribute class-attribute

phone_format: str = 'RFC3966'

The format of the phone number.

min_length instance-attribute class-attribute

min_length: int = 7

The minimum length of the phone number.

max_length instance-attribute class-attribute

max_length: int = 64

The maximum length of the phone number.