Validating Credit Card Numbers

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