RegEx - Usernames

Hi all- I am trying to solve the exercise “Restrict Possible Usernames.” After several attempts, my code still fails one of the tests:


let userCheck = /^[a-z][a-z]+\d*$/i;

**

"Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters. "

**
The way i read my code is:
it should start with at least 2 alphabet letters

^ [a-z][a-z] +

it should end with 0 or more digits

\d*$/ 

it should take upper or lower case.

i

I took a look at the answers and noticed they can include a number after the first letter, but the test asks that if the username is a two-character username, we should use alphabet letters. I also tried using the global character (g) but it wouldn’t work.
Please help! what am i not seeing?

Thank you!

Your code so far


let username = "JackOfAllTrades";
//let userCheck = /\D[a-zA-Z]\d/i; // Change this line
//let userCheck = /^[a-zA-Z.+\d]/ig;
//let userCheck = /\D^[a-zA-Z.+\d]/ig;
//let userCheck = /\D[a-z+]\d*$/i;
//let userCheck = /[a-z]{2,}\d*/gi;
let userCheck = /^[a-z][a-z]+\d*$/i;

let result = userCheck.test(username);
console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36

Challenge: Restrict Possible Usernames

Link to the challenge:

What if you have a username like B007? I don’t think your regex allows the second character to be a number.

1 Like

Yes, it wouldn’t work. I thought the first two had to be letters regardless. Did I misunderstand the instructions?

Thank you so much!

if there is more than two characters only the first character must be a letter, if there are only two characters both have to be letters

Hello everyone! I recommend you this site so you can see what your RegEx matches with.
Hope this can help you @veronicarbulu

Thank you! I think that’s where I got Stuck.

Awesome. Thank you. Much appreciated!

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