strings.credit_card_validator ============================= .. py:module:: strings.credit_card_validator .. autoapi-nested-parse:: Functions for testing the validity of credit card numbers. https://en.wikipedia.org/wiki/Luhn_algorithm Functions --------- .. autoapisummary:: strings.credit_card_validator.luhn_validation strings.credit_card_validator.validate_credit_card_number strings.credit_card_validator.validate_initial_digits Module Contents --------------- .. py:function:: 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 .. py:function:: 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 .. py:function:: 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