Validating Credit Card Numbers

  • + 1 comment
    import re
    
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    test_cases = int(input())
    for num in range(test_cases):
        case = input()
        valid_card_pattern = re.compile(r'^(?!.*(\d)(-*\1){3,})([4-6][0-9]{3}-?([0-9]{4}-?){3})$')
        if valid_card_pattern.match(case):
            print('Valid')
        else:
            print('Invalid')