These are the conditions:
► It must start with a 4, 5 or 6.
► It must contain exactly 16 digits.
► It must only consist of digits (0-9).
► It may have digits in groups of 4, separated by one hyphen “-“.
► It must NOT use any other separator like ‘ ‘ , ‘_’, etc.
► It must NOT have 4 or more consecutive repeated digits.
this is my code, all cases are giving ‘Invalid’ output.
import re
for _ in range(int(input())):
if re.search(r'^(?<=[4-6])(?!.*(.)(-?1){3}.*)(d{4})(-?d{4}){3}$', input()):
print('Valid')
else: print('Invalid')
sample input:
6
4123456789123456
5123-4567-8912-3456
61234-567-8912-3456
4123356789123456
5133-3367-8912-3456
5123 – 3567 – 8912 – 3456
sample output:
Valid
Valid
Invalid
Valid
Invalid
Invalid
rushi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.