Validating Credit Card Numbers

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