Restrict Possible Usernames

Hi, I have a question. Why my code no pass?

let username = "JackOfAllTrades";
let userCheck = /^[a-zA-Z]+[a-zA-Z]\d*$/ig; // Cambia esta línea
let result = userCheck.test(username);

error: Your regex should match the string Z97

I’m very confussed. Please help me

Can you explain a little more about what is confusing you. The error is telling you that your pattern should allow “Z97” but it does not. Do you understand why it doesn’t?

Also, you might want to review the challenge Match a Literal String with Different Possibilities. You can use the pipe operator with more than just strings.

No, I don’t understand. Can you explain me?

Explain to me in plain words what your expression is doing:


^[a-zA-Z] start with and Alphabet character
[a-zA-Z] Alphabet character \d*$ ends with a number

but I can’t link them together. I try with a | operator between them but my code have more errors

Your current pattern:


Matches two or more letters at the beginning of the string and then 0 or more numbers after those letters, so it will not catch the string “Z97” because your pattern requires at least two letters at the beginning.

You are actually off to a good start. This pattern catches almost everything except for “Z97”. So you need to add something to catch the string with only one letter at the beginning and numbers afterwards.

And as I hinted to earlier, you can use the pipe operator to do this.

I think something about:


but it’s wrong

You are so close. Your second pattern is too permissive. Read the fourth requirement again.


I think that, but it’s wrong too :frowning:

I don’t see any changes. The second pattern is too permissive. You need to tighten it up a little.

according to the 4 step. I think in:


but my code still not pass. I’m very frustated. I’m sorry about that

ok. I passed the exercise.


Thanks a lot and I hope to help somebody. Cheers

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.