Restrict Possible Usernames Confusion

Restrict Possible Usernames Confusion
0

#1

Tell us what’s happening:
Hi everyone, I know there are many threads about this topic already, but I couldn’t really find out what I’m doing wrong yet. So here is my solution, but it’s telling me that my regex should match JACK and RegexGuru (I’m sure I already had it match these when the regex didn’t match something else, but I tried so many diffent solutions and now I absolutely confused myself)
I figured in the forum that I need to use {2,}, which wasn’t mentioned in the challenges yet I think, but what is my mistake now?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /^[a-z]{2,}\d*$/ig; // Change this line
let result = userCheck.test(username);

Your browser information:

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

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


#2

I tried your solution in a separate repl (https://stephengrider.github.io/JSPlaygrounds/) and it works, so there must be a bug in the test suite.

However, the ‘^’ and ‘g’ markers aren’t necessary to meet the requirements of this challenge. If you remove the ‘g’ tag, your code should pass. You can optionally keep the ‘^’.


#3

Thank you! I got rid of the g flag and it worked :slight_smile: