Restrict Possible Usernames Explanation

Tell us what’s happening:

Athough i passed the challenge, i don’t have the answer why this syntax " let userCheck = /\D/g; " was correct too.

Your code so far

let username = "JackOfAllTrades";
let userCheck = /\D[0-9]*/g; // Change this line
let result = userCheck.test(username);

Your browser information:

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

Link to the challenge:

It’s natural to feel that way for this challenge because the challenge accepts many incorrect solutions. Bottom line is that the test for this challenge doesn’t check any false positives that violate the given rule set. It doesn’t even strictly check the given rule set.

Your regex says “Match non-digit followed by zero or more digits” and check this globally.
Now based on this, see if your regex will match the following inputs.


These examples violate the rule set from the challenge. However, your regex will happily let them pass.

It is little tricky (or verbose) to get this challenge correct. You will definitely need more than what you learned. So, I’d suggest you just let this one go for now and come back when you have sufficient regex knowledge.

1 Like

I got it! Thanks for your help!