Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Last active September 15, 2023 14:33
Show Gist options
  • Save codeperfectplus/78b5a4205ed665fdd849c2cba8c5f6e1 to your computer and use it in GitHub Desktop.
Save codeperfectplus/78b5a4205ed665fdd849c2cba8c5f6e1 to your computer and use it in GitHub Desktop.
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