Restrict Possible Usernames - Stuck

Tell us what’s happening:
According to regex101.com, my reg expression is correct. But according to FCC it is not. What am I doing wrong?
I have covered the minimum 2 chars at the beginning, only numbers at the end (or zero), and upper and lower case…what did I miss?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /[\D][\D]+[\d]*$/gi; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15.

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

I believe \D is still numbers. \w is both alpha and numeric plus _ as well. Replace it with [a-z] and it should work. Also I don’t believe you need to make it global because there is only one username.

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

1 Like

Thanks for the input. Actually my solution does work, just had to not make it global ! :wink:

As I know, \D is not number which equal to [^0-9]

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

It can pass all in other tools but it cannot pass “JACK” in Freecodecamp…

Anything wrong with this?

Have you tried removing the “g” flag?

Yes thanks . Removing the “g” flag does work in Freecodecamp.

but it still can work with the “g” flag in other tools. why?