strings.credit_card_validator

Functions for testing the validity of credit card numbers.

https://en.wikipedia.org/wiki/Luhn_algorithm

Functions

luhn_validation(→ bool)

Function to luhn algorithm validation for a given credit card number.

validate_credit_card_number(→ bool)

Function to validate the given credit card number.

validate_initial_digits(→ bool)

Function to validate initial digits of a given credit card number.

Module Contents

strings.credit_card_validator.luhn_validation(credit_card_number: str) bool

Function to luhn algorithm validation for a given credit card number. >>> luhn_validation(‘4111111111111111’) True >>> luhn_validation(‘36111111111111’) True >>> luhn_validation(‘41111111111111’) False

strings.credit_card_validator.validate_credit_card_number(credit_card_number: str) bool

Function to validate the given credit card number. >>> validate_credit_card_number(‘4111111111111111’) 4111111111111111 is a valid credit card number. True >>> validate_credit_card_number(‘helloworld$’) helloworld$ is an invalid credit card number because it has nonnumerical characters. False >>> validate_credit_card_number(‘32323’) 32323 is an invalid credit card number because of its length. False >>> validate_credit_card_number(‘32323323233232332323’) 32323323233232332323 is an invalid credit card number because of its length. False >>> validate_credit_card_number(‘36111111111111’) 36111111111111 is an invalid credit card number because of its first two digits. False >>> validate_credit_card_number(‘41111111111111’) 41111111111111 is an invalid credit card number because it fails the Luhn check. False

strings.credit_card_validator.validate_initial_digits(credit_card_number: str) bool

Function to validate initial digits of a given credit card number. >>> valid = “4111111111111111 41111111111111 34 35 37 412345 523456 634567” >>> all(validate_initial_digits(cc) for cc in valid.split()) True >>> invalid = “14 25 76 32323 36111111111111” >>> all(validate_initial_digits(cc) is False for cc in invalid.split()) True