Validating Credit Card Numbers

  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    import re

    N = int(input()) credit_num = [] for _ in range(N): cred = input().strip() # Read each line and strip any extra whitespace credit_num.append(cred) # Append the entire line as a single entry

    for n in credit_num: if (re.match(r'^[4-6]', n) and len(re.sub(r'[^0-9]', '', n)) == 16 and re.match(r'^[0-9-]+Undefined control sequence \d', n) or re.match(r'^\d{16}$', n)) and not re.search(r'(\d)\1{3,}', re.sub(r'[^0-9]', '', n))): print("Valid") else: print("Invalid")