You are viewing a single comment's thread. Return to all comments →
import re pattern1 = r'^[546][0-9]{3}(-?)[0-9]{4}\1[0-9]{4}\1[0-9]{4}$' pattern2 = r'(?!.*(\d)\1{3})' n = int(input()) for i in range(n): s = input() match1 = re.fullmatch(pattern1, s) match2 = re.match(pattern2, re.sub('-', '', s)) if bool(match1 and match2) is True: print('Valid') else: print('Invalid')
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 →