Restrict Possible Usernames-!

Tell us what’s happening:

Can anyone tell me why my code isn’t matching JACK or RegexGuru? I believe it is. In the regex tester it works for JACK and RegexGuru.

Your code so far

let username = "JACK";
let userCheck = /^[a-z]{2,}\d{0,}/ig; // 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.

So to pass the test, get rid of the global flag (/../g). Also, bear mind that (while yours WILL pass) you failed to meet one of the stipulations:

The only numbers in the username have to be at the end. There can be zero or more of them at the end.

You are checking for two or more letters, followed by zero or more numbers – but that isn’t restricting the numbers to the end of the string.

Thank you! I see now. I ended up with

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

By removing the global case what exactly does that do? Just makes it so it can’t find it anywhere in the string? I’m a little confused by that if you could explain.

Global is useful if you’re looking for multiple instances, or looking across multple lines. In this case, not so much.