We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importre# Function to validate credit card numbersdefvalidate_credit_card(card_number):pattern=r'^[456]\d{3}(-?\d{4}){3}$'# Regex pattern for a valid card number# Check if the card matches the pattern and has no consecutive repeated digitsifre.match(pattern,card_number)andnotre.search(r'(\d)\1{3,}',card_number.replace('-','')):return"Valid"else:return"Invalid"no_of_cards=int(input())card_numbers=[input()for_inrange(no_of_cards)]# Applying the function to each card numberresults=[validate_credit_card(card)forcardincard_numbers]forresultinresults:print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Credit Card Numbers
You are viewing a single comment's thread. Return to all comments →