Validating Credit Card Numbers

  • + 1 comment
    import re
    pattern = r'^(?!.*(\d)(-*\1){3,})([456][0-9]{3}-?([0-9]{4}-?){3})$'
    
    for _ in range(int(input())):
        print("Valid") if re.match(pattern, input()) else print("Invalid")