Last active
September 15, 2023 14:33
-
-
Save codeperfectplus/78b5a4205ed665fdd849c2cba8c5f6e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# compile the patterns | |
pattern = re.compile( | |
r'^' | |
r'(?!.*(\d)(-?\1){3})' | |
r'[456]\d{3}' | |
r'(?:-?\d{4}){3}' | |
r'$') | |
# validating credit card numbers | |
def validate_credit_card_number(card_number): | |
if pattern.match(card_number): | |
return 'Valid' | |
else: | |
return 'Invalid' | |
# main function | |
if __name__ == '__main__': | |
N = int(input()) | |
for _ in range(N): | |
card_number = input() | |
print(validate_credit_card_number(card_number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment