You are viewing a single comment's thread. Return to all comments →
I thought it should be done with a single regex, and turns out it can be done:
import re [print('Valid') if re.match(r'^(?!.*(.).*\1)(?=(?:.*[A-Z]){2,})(?=(?:.*\d){3,})[a-zA-Z0-9]{10}$', input()) else print('Invalid') for _ in range(int(input()))]
Explanation:
(?!.*(.).*\1)
(?=(?:.*[A-Z]){2,})
(?=(?:.*\d){3,})
[a-zA-Z0-9]{10}
Inspiration taken from this stackoverflow question.
PS: Since I use re.match, the ^ at the beginning is unnecessary but I put it there anyway out of good habit.
Seems like cookies are disabled on this browser, please enable them to open this website
Validating UID
You are viewing a single comment's thread. Return to all comments →
I thought it should be done with a single regex, and turns out it can be done:
Explanation:
(?!.*(.).*\1)
checks no repeating characters;(?=(?:.*[A-Z]){2,})
checks at least 2 uppercase letters;(?=(?:.*\d){3,})
checks at least 3 digits;[a-zA-Z0-9]{10}
checks exactly 10 alphanumeric characters.Inspiration taken from this stackoverflow question.
PS: Since I use re.match, the ^ at the beginning is unnecessary but I put it there anyway out of good habit.