Restrict Possible Usernames help

it should not be matching with usernames which have more than two numbers pls help

Your code so far

let username = "JackOfAllTrades";
let userCheck = /\w/g; // Change this line
let result = userCheck.test(username);

Your browser information:

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

Link to the challenge:

right now your regex is not sufficient to solve this problem.

I think I suggested this website to you before:

you go there to test your regex and discover how it works

For eg. when I typed your regex into the website, and the test string “JackOfAllTrades” it matched all the characters (one by one)

If i change your regex to \w+ then it matches the whole word as one block.

if i then change the test string to “JackOfAllTrades999”, it still matches the whole thing as correct (one entity match).

So instead of using \w which is matching this [A-Za-z0-9_]
maybe you can use something more specific to match alphabet only
maybe you can combine that with an OR to allow for different kinds of matches (ones with numbers, ones without)

just some ideas…

ps. there is known bug in this section also so make sure your solution does not use /g flag

i have been using regextester and lol i just logged in and put in /\w\D/g so it worked. I didnt expect because both numbers and text is expected and i would have to put ^\D to exclude stuff which does not have numbers in the beginning so i am still confused how this worked

I’m glad you’re using regextester now but I’m not sure what you mean, I tried \w\D and it will not give a single match for any of the given values for this challenge.

Eg. try it with the word ‘JACK’ and it will match JA and CK as two separate pieces.
(you want it to match the whole word, not pieces of the word)

just want to re-iterate also that there is an issue with this challenge, so when you come up with a solution, don’t use global flag.

cleared the challenge again with /^[a-z]\D/ i but regex tester says no match

Sigh. There is a known issue with the challenge and it allows incorrect regex to pass in certain cases (I didn’t read the details). I wouldn’t worry about it unless you really want to understand the topic.

is it with other challenges in the regex section too? because i am not able to complete a challenge of ranged regex but in regextester it passes all the tests

I think each challenge is different because a different program is invoked each time

uh okay ill try to figure out the usename challenge anyway thanks a lot for the help!