Restrict Possible Usernames solution

let username = "JACK";

let userCheck = /^[a-z]{2,}\d*$/ig; // Change this line

let result = userCheck.test(username);


I was wondering why the solution does not match “Jack”, and “Jo”, yet it returns true in the console

I have added the link for the challenge.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

:laughing: :laughing: I will remember that.

Hey there,

There is a known issue with this challenge where using the g flag on your regex causes test failures. For what it’s worth, this isn’t a situation where you would need the g flag anyway, since you are looking at the entire string.

Try removing that g flag and you should see some more accurate results. :slight_smile:

1 Like

It worked. Thank you. What exactly is the issue with the g flag?

you can see here in the documentation: RegExp.prototype.test() - JavaScript | MDN

in short, if you use the g flag, the index at which the string starts to be checked changes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.