TL; DR
The logic in this challenge is, as far as I can tell, self-contradicting: Regular Expressions: Restrict Possible Usernames. Username 007
fulfils all the written requirements for usernames, but is expected to fail the regex check. I suggest the wording of the third username requirement be amended to accurately reflect the unwritten requirement: “there should be at least two alphabet characters at the start of the username”.
Read on…
The description text places the following requirements on usernames:
- The only numbers in the username have to be at the end. There can be zero or more of them at the end.
- Username letters can be lowercase and uppercase.
- Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.
The expected results are:
- Your regex should match
JACK
- Your regex should not match
J
- Your regex should match
Oceans11
- Your regex should match
RegexGuru
- Your regex should not match
007
- Your regex should not match
9
The problem
As far as I can tell, 007
fulfils all the requirements for usernames, but is expected to fail.
- Numbers only at the end? True. They’re also at the beginning, but that’s because there are no letters
- Zero or more numbers? True.
- Letters not case-sensitive? True. There are no letters, but nowhere does it say we are required to have letters.
- At least two characters long? True.
- If two characters long, are both characters letters? Not applicable; the username is more than two characters long.
The regex suggested in the “hint” page is this:
let userCheck = /^[a-z]{2,}\d*$/i;
The ^[a-z]{2,}
part means “there must be at least 2 alphabet characters at the start of the username”. This requirement is not clearly communicated in the challenge. I suggest the wording of the third username requirement be amended to accurately reflect the unwritten requirement: “there should be at least two alphabet characters at the start of the username”.