Problem with the challenge

Tell us what’s happening:

I am using the source:


and tried to make a code that did follow the requirments
yer can’t’ figure it out

Your code so far


let username = "JackOfAllTrades";
let userCheck = [a-z]/d/g; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15.

Challenge: Restrict Possible Usernames

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

a regex includes the pattern inside /, and after that there are the flags
so you should write /pattern/flags
is there something missing in your code?

1 Like

Matches any digit is \d not /d if that is what you wanted (Character classes).

1 Like

Hello Kora.

When defining a regular expression, you need to start with a forward slash. You indicate the end of the regex also with a /. After which, you define your parameters (eg. g, i).

const reg = /password/g;

If you are wanting to make use of a character class, you need to escape literal strings using a backslash.

const reg = /string\d/gi;

The above will be interpreted in the following way:

  1. / Opens a regular expression
  2. string is interpreted as literally “string”
  3. \ escapes literal strings
    b. d is interpreted as any numeric digit
  4. / indicates the end of the expression
  5. g is a flag that indicates the declared expression is to be used globally
  6. i is a flag that indicates the declared expression is case insensitive.

I hope that makes sense.

1 Like

Thanks for the fast reply all :cat: i was able to solve it <3