Regex Possible Usernames

I can’t pass the test “Your regex should match Z97”

Your code so far


let username = "JackOfAllTrades";
let userCheck = /^[A-Za-z]{2,}\d*$/; // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Restrict Possible Usernames

Link to the challenge:

1 Like

```1. ^ - start of input
2. [a-z] - first character is a letter
3. [0-9][0-9]+ - ends with two or more numbers
4. | - or
5. [a-z]+ - has one or more letters next
6. \d* - and ends with zero or more numbers
7. $ - end of input
8. i - ignore case of input`

This might give you a hint as to what you should do. (A very broad hint)

I don’t think that regex described above quite matches the problem description. There are good pieces though.

When I did this the first time, it helped me to write two regex, one for each of the two possible patterns, and then to | the two regex.

This is the requirement that tells you what the two possible cases:

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

I’d start by describing the two possible groups of usernames: Group 1 starts with _______ and has at least _____ characters while Group 2 starts with______ and has at least ______ characters

1 Like