Validating Credit Card Numbers

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