Restrict Possible Usernames: incorrect problem description?

The Restrict Possible Usernames assignment asks you to write a regexp for a username that meets the following criteria:

  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.

I came up with:

let userCheck = /^[a-z]{2,}\d*$|^[a-z]\d{2,}$|^\d{3,}$/i; 
let result = userCheck.test(username);

But the check algorithm says “Your regex should not match 007”. I believe this is incorrect. By the above criteria, 007 is a valid username. All the numbers are at the end. It’s at least two characters long. It is not a two-letter username and so it does not need to use only alphabet letter characters.

I think what’s intended in (3) is that the first two letters of the username should be alphabet letters. But that’s not what the problem says. So this should be changed. Would my solution work for the problem as written? (It’s really clunky, but I can’t find anything more elegant.)

(Also, I note that the solution given in the hints section uses curly brackets, which haven’t been taught yet. I think the solution for the intended question should be given as /[a-z][a-z]+\d*$/i ).

You can be a hero and create an issue in their repo :slight_smile:

Good idea! I went ahead and did it. :slight_smile:

007 is not a valid username by the above criteria. The first and third criteria explicitly state that

  1. The only numbers in the username have to be at the end.
  2. A two-letter username can only use alphabet letter characters.

That implies that a username can be 2 letters at the minimum, and that those letters could only possibly be alphabetical characters because the username cannot begin with a numeric.
The correct solution is:

/^[a-z]{2, }\d*$/i

Or, according to what we already learnt,

/^[a-z]+[a-z]+\d*$/i

Either should pass the test according to the criteria and hints given.

That’s not right. The second criterion in your list puts restrictions on two-letter (two-character) usernames. But 007 is not a two-letter (or two-character) username. It’s a three-character username. So that restriction doesn’t apply to it at all.

I think you’re describing the intent of the problem. We’re supposed to understand that the first two characters of a username must be alphabet letters. But that’s not what the problem actually says, and it’s not implied by what the problem says.

Yes, I suppose if you complete the challenges without looking at the hints regarding the results that should be returned, the instruction should’ve included that the first two letters must be alphabetical only.