Editor

Valid Username

#234 · Regular expressions · Beginner · 30 XP · about 5 min

A sign-up form accepts a username only when it follows these rules:

  • It is 3 to 16 characters long.
  • It uses only English letters (a to z, in either case), the digits 0 to 9 and underscores.
  • Its first character is a letter.

Write is_valid_username(name) that returns True if name follows every rule and False if it breaks any of them.

Examples

is_valid_username('alice_99')   # returns True
is_valid_username('9lives')     # returns False
is_valid_username('al')         # returns False
is_valid_username('jo-jo')      # returns False

The second name starts with a digit, the third is too short, and the last one contains a dash.

Note

Any other character makes the name invalid, including spaces, accented letters such as é, and a line break at the end.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.