$51 GRAYBYTE WORDPRESS FILE MANAGER $22

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 147.79.69.216 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python311/lib/python3.11/site-packages/validators/

HOME
Current File : /opt/alt/python311/lib/python3.11/site-packages/validators//card.py
"""Card."""

# standard
import re

# local
from .utils import validator


@validator
def card_number(value: str, /):
    """Return whether or not given value is a valid generic card number.

    This validator is based on [Luhn's algorithm][1].

    [1]: https://github.com/mmcloughlin/luhn

    Examples:
        >>> card_number('4242424242424242')
        # Output: True
        >>> card_number('4242424242424241')
        # Output: ValidationError(func=card_number, args={'value': '4242424242424241'})

    Args:
        value:
            Generic card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid generic card number.
        (ValidationError): If `value` is an invalid generic card number.
    """
    if not value:
        return False
    try:
        digits = list(map(int, value))
        odd_sum = sum(digits[-1::-2])
        even_sum = sum(sum(divmod(2 * d, 10)) for d in digits[-2::-2])
        return (odd_sum + even_sum) % 10 == 0
    except ValueError:
        return False


@validator
def visa(value: str, /):
    """Return whether or not given value is a valid Visa card number.

    Examples:
        >>> visa('4242424242424242')
        # Output: True
        >>> visa('2223003122003222')
        # Output: ValidationError(func=visa, args={'value': '2223003122003222'})

    Args:
        value:
            Visa card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid Visa card number.
        (ValidationError): If `value` is an invalid Visa card number.
    """
    pattern = re.compile(r"^4")
    return card_number(value) and len(value) == 16 and pattern.match(value)


@validator
def mastercard(value: str, /):
    """Return whether or not given value is a valid Mastercard card number.

    Examples:
        >>> mastercard('5555555555554444')
        # Output: True
        >>> mastercard('4242424242424242')
        # Output: ValidationError(func=mastercard, args={'value': '4242424242424242'})

    Args:
        value:
            Mastercard card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid Mastercard card number.
        (ValidationError): If `value` is an invalid Mastercard card number.
    """
    pattern = re.compile(r"^(51|52|53|54|55|22|23|24|25|26|27)")
    return card_number(value) and len(value) == 16 and pattern.match(value)


@validator
def amex(value: str, /):
    """Return whether or not given value is a valid American Express card number.

    Examples:
        >>> amex('378282246310005')
        # Output: True
        >>> amex('4242424242424242')
        # Output: ValidationError(func=amex, args={'value': '4242424242424242'})

    Args:
        value:
            American Express card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid American Express card number.
        (ValidationError): If `value` is an invalid American Express card number.
    """
    pattern = re.compile(r"^(34|37)")
    return card_number(value) and len(value) == 15 and pattern.match(value)


@validator
def unionpay(value: str, /):
    """Return whether or not given value is a valid UnionPay card number.

    Examples:
        >>> unionpay('6200000000000005')
        # Output: True
        >>> unionpay('4242424242424242')
        # Output: ValidationError(func=unionpay, args={'value': '4242424242424242'})

    Args:
        value:
            UnionPay card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid UnionPay card number.
        (ValidationError): If `value` is an invalid UnionPay card number.
    """
    pattern = re.compile(r"^62")
    return card_number(value) and len(value) == 16 and pattern.match(value)


@validator
def diners(value: str, /):
    """Return whether or not given value is a valid Diners Club card number.

    Examples:
        >>> diners('3056930009020004')
        # Output: True
        >>> diners('4242424242424242')
        # Output: ValidationError(func=diners, args={'value': '4242424242424242'})

    Args:
        value:
            Diners Club card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid Diners Club card number.
        (ValidationError): If `value` is an invalid Diners Club card number.
    """
    pattern = re.compile(r"^(30|36|38|39)")
    return card_number(value) and len(value) in {14, 16} and pattern.match(value)


@validator
def jcb(value: str, /):
    """Return whether or not given value is a valid JCB card number.

    Examples:
        >>> jcb('3566002020360505')
        # Output: True
        >>> jcb('4242424242424242')
        # Output: ValidationError(func=jcb, args={'value': '4242424242424242'})

    Args:
        value:
            JCB card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid JCB card number.
        (ValidationError): If `value` is an invalid JCB card number.
    """
    pattern = re.compile(r"^35")
    return card_number(value) and len(value) == 16 and pattern.match(value)


@validator
def discover(value: str, /):
    """Return whether or not given value is a valid Discover card number.

    Examples:
        >>> discover('6011111111111117')
        # Output: True
        >>> discover('4242424242424242')
        # Output: ValidationError(func=discover, args={'value': '4242424242424242'})

    Args:
        value:
            Discover card number string to validate

    Returns:
        (Literal[True]): If `value` is a valid Discover card number.
        (ValidationError): If `value` is an invalid Discover card number.
    """
    pattern = re.compile(r"^(60|64|65)")
    return card_number(value) and len(value) == 16 and pattern.match(value)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
5 Sep 2025 9.32 AM
root / 996
0755
__pycache__
--
8 May 2024 6.34 PM
root / root
0755
i18n
--
8 May 2024 6.34 PM
root / root
0755
__init__.py
1.86 KB
8 May 2024 6.34 PM
root / root
0644
_extremes.py
1.014 KB
8 May 2024 6.34 PM
root / root
0644
_tld.txt
9.401 KB
8 May 2024 6.34 PM
root / root
0644
between.py
2.387 KB
8 May 2024 6.34 PM
root / root
0644
btc_address.py
1.616 KB
8 May 2024 6.34 PM
root / root
0644
card.py
5.631 KB
8 May 2024 6.34 PM
root / root
0644
country.py
14.569 KB
8 May 2024 6.34 PM
root / root
0644
cron.py
2.228 KB
8 May 2024 6.34 PM
root / root
0644
domain.py
2.401 KB
8 May 2024 6.34 PM
root / root
0644
email.py
2.723 KB
8 May 2024 6.34 PM
root / root
0644
encoding.py
1.337 KB
8 May 2024 6.34 PM
root / root
0644
finance.py
3.222 KB
8 May 2024 6.34 PM
root / root
0644
hashes.py
3.21 KB
8 May 2024 6.34 PM
root / root
0644
hostname.py
4.046 KB
8 May 2024 6.34 PM
root / root
0644
iban.py
1.054 KB
8 May 2024 6.34 PM
root / root
0644
ip_address.py
4.341 KB
8 May 2024 6.34 PM
root / root
0644
length.py
1.45 KB
8 May 2024 6.34 PM
root / root
0644
mac_address.py
0.845 KB
8 May 2024 6.34 PM
root / root
0644
py.typed
0 KB
8 May 2024 6.34 PM
root / root
0644
slug.py
0.732 KB
8 May 2024 6.34 PM
root / root
0644
uri.py
1.777 KB
8 May 2024 6.34 PM
root / root
0644
url.py
7.231 KB
8 May 2024 6.34 PM
root / root
0644
utils.py
3.103 KB
8 May 2024 6.34 PM
root / root
0644
uuid.py
1.039 KB
8 May 2024 6.34 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF