Regexp exercice: "Restrict Possible Usernames"

Tell us what’s happening:

I think I’m getting better and better with regular expressions every day. But I’m stil missing something in this exercice: this condition -> Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.

There is no reglar expression syntax that allows to specific nth time a character has to repeat if I recall…Or am I wrong?

Your code so far

let username = "JackOfAllTrades";
let userCheck = /[a-zA-Z]\d*$/; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0.

Link to the challenge:


I went through these challenges myself not so long ago and got stuck on the same problem.
You can use “X{n}” to check if X matches n times.

You can see a bit of documentation on it here

Good luck!

Yes it worked with X{n}! Thanks! But this new syntax comes later in the exercices, and is not yet intrioduced in this exercice, and that is why I wasn’t able to find the solution.

It was introduced here:

I don’t want to create a new thread for this other problem but is there a bug in FCC with this exercice?

The error message is “Your regex should not match “Ohhhhhhh no””

But the {3,6} is 3 to 6 times inclusive, right?
My code

let ohStr = "Ohhh no";
let ohRegex = /h{3,6}/; // Change this line
let result = ohRegex.test(ohStr);

Your latest code above will return true if there are 3, 4, 5, of 6 consecutive “h” found in ohStr.

I think that the test case you most likely weren’t passing is this:

Your regex should not match J

In order words, the Username can’t be a single character string. Doing the below should get you through.

let username = "JackOfAllTrades";
let userCheck = /\w[a-zA-Z]\d*$/; // Change this line
let result = userCheck.test(username);

I hope this helps! :slight_smile:

let userCheck = /[a-zA-Z]+\w+$/; You can use this it works perfectly fine

hi @De-Bee, i just wanted to know which one is the best approach while validating emails with joi or regular expressions. Thanks :slight_smile: