Restrict Possible Usernames - edge case failure

The tests for this challenge seem to miss one edge case. The code I have passes all the tests given.

I think for example a username of “J007” should match given the spec. It is more than 2 characters long so only the first character needs to be a letter.

However, I can’t figure out how to make that pass, but also have the restriction that a two character username should only have letters (i.e. “J7” should not be a match).

I could just submit and carry on, but I’d love to know how to fix this corner case too

Your code so far

let username = "JackOfAllTrades";
let userCheck = /^[a-z]{2,}\d*$/i; // Change this line
let result = userCheck.test(username);
console.log(userCheck.test("J007")==true); \\should pass but fails

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:

Yeah, it’s possible that the spec isn’t clear. If I always require at minimum 2 letters at the beginning then all of the given tests pass. It’s just that seems to contradict the written spec. As a product manager I’ve written my fair share of ambiguous user stories :blush: so maybe the text should be updated.

But, I’d still be interested if there is a way to make a regex that passes for J123 and JA but not J1, I can’t figure one out.

That regex would be /^[a-z](\d{2,}|[a-z]+\d*)$/i

However, the regex course doesn’t cover alternation (the | character), so the docs and/or tests should change to eliminate the edge case.

Ah great, that makes sense.

Thanks very much