Valid Username
Return True if name is a valid username, otherwise False. All of these rules must hold:
- The length is 3 to 16 characters.
- The first character is a lowercase letter.
- Every character is a lowercase letter, a digit or an underscore
_. - Two underscores are never next to each other.
- The last character is not an underscore.
Example 1
name "alice_01"
returns true
Eight characters, starts with a letter, one underscore not at the end.
Example 2
name "Alice"
returns false
The first character is an uppercase letter.
Example 3
name "a__b"
returns false
Two underscores sit next to each other.
Constraints
0 <= len(name) <= 20namehas letters, digits, spaces and the symbols_and-only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Well-Formed SumEasy
- Add the FractionsMedium
- Count and SayMedium
- Expand Character RangesMedium
- Falling DominoesMedium
- Fit the Capital PatternMedium
- Kth Letter of the Unpacked TextMedium
- Solve for xMedium