Regexp username

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:

First of all, those spaces you have around the pipe are causing you grief. Spaces are treated as a character, they are not ignored, so you need to get rid of the one before the pipe since usernames cannot have spaces in them. The one after the pipe I don’t think is causing problems since you’re using the caret but I would remove anyway.

After you remove these spaces you’ll be down to two errors. My hint is that you are doing a good job of using the caret to define the start of the match but perhaps you need to define the end as well?

Thanks a lot. My real issue was the spaces. I included the dollar sign character in the thinking process but forgot to type them out.