MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / validate_initial_digits

Function validate_initial_digits

strings/credit_card_validator.py:8–18  ·  view source on GitHub ↗

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_ini

(credit_card_number: str)

Source from the content-addressed store, hash-verified

6
7
8def validate_initial_digits(credit_card_number: str) -> bool:
9 """
10 Function to validate initial digits of a given credit card number.
11 >>> valid = "4111111111111111 41111111111111 34 35 37 412345 523456 634567"
12 >>> all(validate_initial_digits(cc) for cc in valid.split())
13 True
14 >>> invalid = "14 25 76 32323 36111111111111"
15 >>> all(validate_initial_digits(cc) is False for cc in invalid.split())
16 True
17 """
18 return credit_card_number.startswith(("34", "35", "37", "4", "5", "6"))
19
20
21def luhn_validation(credit_card_number: str) -> bool:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected