Validating Credit Card Numbers

  • + 0 comments
    import re
    p = r'^[456]\d{3}(-?\d{4}){3}$'
    for _ in range(int(input())):
        s  = input()
        if re.match(p, s):
            s = s.replace('-', '')
            if not re.search(r'(.)\1{3}', s):
                print("Valid")
            else:
                print("Invalid")
        else:
            print("Invalid")