Validate with fullmatch
Completed
A valid username is 3–16 characters, starts with a letter, and contains only letters, digits and underscores. Read usernames and print valid or invalid.
Input
Line 1: n. Then n usernames.
Output
n lines.
Example
Input
5 ada_99 9lives ab this_name_is_way_too_long OK_go
Output
valid invalid invalid invalid valid
Editor
Python
Hints
fullmatch requires the whole string to match.
{2,15} repeats the previous token 2 to 15 times.
Solution explanation
re.compile builds the pattern once when you reuse it many times.
Show solution
import re
pattern = re.compile(r"[A-Za-z]\w{2,15}")
for _ in range(int(input())):
print("valid" if pattern.fullmatch(input()) else "invalid")