Skip to main content
Pydantic Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Payment

The pydantic_extra_types.payment module provides the PaymentCardNumber data type.

Bases: str, Enum

Payment card brands supported by the PaymentCardNumber.

Bases: str

A payment card number.

Whether to strip whitespace from the input value.

Type: bool Default: True

The minimum length of the card number.

Type: int Default: 12

The maximum length of the card number.

Type: int Default: 19

The first 6 digits of the card number.

Type: str Default: card_number[:6]

The last 4 digits of the card number.

Type: str Default: card_number[(-4):]

The brand of the card.

Type: PaymentCardBrand Default: self.validate_brand(card_number)

The masked card number.

Type: str

@classmethod

Python
def validate(
    cls,
    __input_value: str,
    _: core_schema.ValidationInfo,
) -> PaymentCardNumber

Validate the PaymentCardNumber instance.

PaymentCardNumber -- The validated PaymentCardNumber instance.

__input_value : str

The input value to validate.

_ : core_schema.ValidationInfo

The validation info.

@classmethod

Python
def validate_digits(cls, card_number: str) -> None

Validate that the card number is all digits.

None

card_number : str

The card number to validate.

  • PydanticCustomError -- If the card number is not all digits.

@classmethod

Python
def validate_luhn_check_digit(cls, card_number: str) -> str

Validate the payment card number. Based on the Luhn algorithm.

str -- The validated card number.

card_number : str

The card number to validate.

  • PydanticCustomError -- If the card number is not valid.

@staticmethod

Python
def validate_brand(card_number: str) -> PaymentCardBrand

Validate length based on [BIN](https://en.wikipedia.org/wiki/Payment_card_number#Issuer_identification_number_(IIN\)) for major brands.

PaymentCardBrand -- The validated card brand.

card_number : str

The card number to validate.

  • PydanticCustomError -- If the card number is not valid.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu