Restrict Possible Usernames mine

Tell us what’s happening:

plz i need a simply explanation for this just want to knw if i am getting it right plz

Your code so far


let username = "JackOfAllTrades";
let userCheck = /\w\D/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/71.0.3578.98 Safari/537.36.

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

Your regex is pretty general – what it’s saying is “any word of whatever length followed by anything that’s not a number”. Does that match the requirements?

I strongly recommend using a regex checker. You can build your regex right in the text box, and see what the changes mean (usually in real-time). I personally use https://www.regextester.com/ quite a lot. In fact, if you use this one: https://www.regextester.com/?fam=107333, I’ve already set it up with all the test cases you’ll need to be checking.

So back to your regex: you know you need at least two alphabetic characters, case insensitive, followed by zero or more numbers. And those numbers MUST be at the end of the string, if there are any. Can yo think of what would give you each of those requirements?

Lastly, you won’t need the /.../g flag on this one, as you’re only looking for a single occurence (not a global many-many possibles). You may want to use the /.../i flag, for case-insensitive, but that should be the only one you might need.