Restrict Possible Usernames - Char Quantities

Tell us what’s happening:
Is there a way to specify the number of chars you want in a field. So I want to regex to specify that there must be 2 or more [a-z] chars at the start of the string. I know there is + for one or more and * for zero or more. How about for other numeric values?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /$[a-z]d*$/i; // 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/76.0.3809.100 Safari/537.36.

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

Challenge link: Regular Expressions: Specify Exact Number of Matches

Oh! Thanks! It got confusing since the solution to this challenge uses a skill which isn’t taught yet. But there almost always more efficient ways to solve any problem. :smile:

Good luck!

you know the character for one or more, you can totally make it without the quantifiers
if you need “two or more” just add one to “one or more”

/\d+/;        // one or more digits
/\d\d+/;    // two or more digits

The challenges and their order have changed over the years, and the solutions are written by volunteers, so they sometimes include methods that you may not have learned from fcc.