What is missing in my Regex?

Tell us what’s happening:
Hi guys.
I don’t really understand what I have missed. I’ve already seen the solution but
I’d like to know what was my mistake.

Thank you in advance.
Wish you a good day :slight_smile:

Your code so far

let username = "JackOfAllTrades";
let userCheck = /^[A-Za-z][A-Za-z]+|^[A-Za-z][A-Za-z]+\d+$/; // Change this line
let result = userCheck.test(username);

**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36</code>.

**Challenge:** Restrict Possible Usernames

**Link to the challenge:**

Hi @Mbonewill,

I just ran your code, and it is failing the test for BadUs3rnam3.
This is because you are using the OR | operator. The second option of your regex /^[A-Za-z][A-Za-z]+\d+$/ searches for strings that start with 2 or more alphabets and end with 1 or more digits, the aforementioned username fails this because it has a 3 between alphabets, which is what you want. However, the first option /^[A-Za-z][A-Za-z]+/ searches for strings which start with 2 or more alphabets, so it matches BadUs3rnam3. Remember for OR statements only one condition needs to be matched for the statement to be true,

1 Like

Ok I got it ! Thank you very for taking the time to answer :slight_smile:
Best wishes man !!

Best wishes to you too, welcome to the forum :slightly_smiling_face:

1 Like