I do not know why the |
operator is not working as I expected. My line of reasoning is the following:
We have to start with a letter and end with zero or more digits. We can accomplish this using the regex ^[a-z][a-z]+[0-9]*
, but this regex does not account for the possibilities where we have the second character as a digit, so we have to include that in another regex combining the two with an OR operator. The second regex should also match what starts with a letter and should have the second character as a number that could extend but when it is only one character this would fall so we need to include another digit character so I use the regex ^[a-z][0-9]+[0-9]
.
So what is wrong with the code?
Your code so far
let username = "JackOfAllTrades";
let userCheck = /^[a-z][a-z]+[0-9]* | ^[a-z][0-9]+[0-9]/i; // Change this line
let result = userCheck.test(username);
Challenge: Restrict Possible Usernames
Link to the challenge: