You are viewing a single comment's thread. Return to all comments →
import re
def is_valid(crd_no):
pattern = r"^(?!.*(\d)(?:-?\1){3})([4-6]\d{3}(-?\d{4}){3})$"
return bool(re.match(pattern, crd_no))
n = int(input())
crd_no = [input() for _ in range(n)]
for card in crd_no:
result = is_valid(card) if result:
print("Valid")
lse: print("Invalid")
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Credit Card Numbers
You are viewing a single comment's thread. Return to all comments →
import re
def is_valid(crd_no):
pattern = r"^(?!.*(\d)(?:-?\1){3})([4-6]\d{3}(-?\d{4}){3})$"
return bool(re.match(pattern, crd_no))
n = int(input())
crd_no = [input() for _ in range(n)]
for card in crd_no:
result = is_valid(card) if result:
lse: print("Invalid")