Mistake in challenge: Restrict Possible Usernames?

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:

  1. The only numbers in the username have to be at the end. There can be zero or more of them at the end.
  2. Username letters can be lowercase and uppercase.
  3. 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”.

Hi @camperextraordinaire, thanks for your response. I don’t understand your logic though.

Could you please give me your definition of “at the end”?

Neither of the zeroes in 007 are the final character, but this shouldn’t be a problem, because the 9 in Z97 isn’t the final character either, and that’s a valid username.

I have taken the rule to mean “any numbers in the username have to be in one contiguous block at the end of the username”. We could also define it with the rule: “a letter can never follow a number”. Both of these statements are true concerning 007.

Regarding this statement:

If that is the intended meaning, then it is not clear in my opinion. It doesn’t explicitly forbid numbers being at the beginning. In the case where the username has no letters, the numbers are at the end (satisfying requirement 1) and at the beginning.

Anyway, the logic in the challenge description and your post implies that usernames must have at least one letter, but this is never actually spelled out anywhere.