Open jmpark0118 opened 3 years ago
import re
if __name__ == '__main__':
for _ in range(int(input())):
card = input()
rule1 = re.match(r'(\d){4}(-){0,1}(\d){4}(-){0,1}(\d){4}(-){0,1}(\d){4}$', card)
if rule1 is None:
print("Invalid")
else:
card = card.replace('-','')
if int(card[0]) not in [4,5,6]:
print("Invalid")
elif re.search(r'(\d)\1{3}', card) is not None:
print("Invalid")
else:
print("Valid")
출처 : https://www.hackerrank.com/challenges/validating-credit-card-number/problem