Validating Credit Card Numbers

  • + 0 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")