Restrict Possible Usernames how this pass the test cases

Tell us what’s happening:

Your code so far

let username = "JackOfAllTrades";
let userCheck = /[a-z]/ig; // 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/71.0.3578.98 Safari/537.36.

Link to the challenge:

Regex is hard stuff. This one requires you to use much of what you have already learned all in one regular expression. You may need to go back to previous challenges to review.

You can take your regex for a test drive here This will help you visualize how you expression is matched against the test passwords.

I will say that I don’t agree with the wording of the challenge.
I think “must have two or more letters, either case” and “can have numbers but only at the end” would be clearer. As I read the current limitations 007 should pass. It is not a two letter username and it has more than two characters

1 Like

Regex - This is great site to try Regex out while to making them, also you have access to all available tokens.

  1. The only numbers in the username have to be at the end. There can be zero or more of them at the end.

  2. Username letters can be lowercase and uppercase.

  3. Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.

  1. \d will check for digits, * will look for zero or more.

  2. This can be solved using the /i flag. Which make the match insensetive.

  1. The username needs a minimum of 2 characters and if the lenght is 2 it can’t be any numbers.
    ^ - will check the start of the word.
    [a-z] will check for letters a-z.
    {2,} will check for length of 2 or more.

Finally ending with a $ will make it end the string.
so between ^ - start and $ - end these rules will match.

^ - start of string, look for any letter a-z, 2 or more. Then check for a random number zero or more times, end string. Insensetive of lower or upper case.

1 Like