Restrict Possible Usernames Regex challenge

Tell us what’s happening:
I don’t know if this is wrong, but it’s passing the tests. As per my understanding, /[A-Za-z][A-Za-z]+\d*$/ makes it compulsory to have 2 letters at the start. However, the challenge doesn’t ask for the 1st 2 characters to be letters - it is only in the case of a 2 character string that both need to be letters.

So J90 should be a valid case, but for this, my regex will not match. Or perhaps the task description needs to be updated to specifically mention 2 or more letters at the start.?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /[A-Za-z][A-Za-z]+\d*$/; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames/

You’re right that the tests are incomplete and that “J90” would be a valid username according to the requirements. Tests are never exhaustive (they can’t be), but you can make a suggestion in the form of a GitHub Issue to improve these tests.

So how could I modify the expression to get a positive match for “J90” as well?

I would call it more of a deficiency in the documentation rather than an edge case that needs to be covered. In other words, “J90” should probably not pass. Getting this to pass would require an alternation (the | character) but that’s not covered in the regex curriculum.

OK, got it. Thanks @chuckadams and @ArielLeslie