Stuck on Restrict Possible Usernames Challenge

Hello!

I am stuck on solving the regex for all username constraints - the is the latest regex i came up with that fits all constraints except Not matching A1.

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

Logic -
^[a-z] + username must begin with a alphabet letter and occurs more than once
[a-z|0-9] character can be alphabet letter or number
\d*$ number can exsist 0 or more times at end of username

I am finding it difficult to meet the constraint of a 2 character username using only alphabet characters, but also allowing the second character to be a number if the username is > 2 characters.

I tried removing the OR quantifier with the following code:

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

but then username Z97 does not pass the test.

I feel like I am missing something very obvious… If anyone has any pointers and tips would be very helpful and much appreciated!

Thanks!
Julie

Hey there,

You are very close. This regex is good. let userCheck = /^[a-z][a-z]+\d*$/i;

Rather than modifying that, you can expand upon that with the | operator.

Hint:

let userCheck = /^[a-z][a-z]+\d*$|(second regex here)/i;
You can write a second regex to match the one letter, two numbers condition.

1 Like

Aha! That was a huge help… Got it! I ended up adding my first regex as the second on after the Or Operator:

/^[a-z][a-z]+\d*|^[a-z]+[a-z|\d][\w]/i;

and that passed!

Thanks again :smiley:

1 Like

Congratulations. Keep up the great work, and happy coding.

I’m going to blur your solution, to avoid potentially spoiling it for another camper who comes here with a similar question.

1 Like