Regular Expressions - Restrict Possible Usernames

Tell us what’s happening:
Describe your issue in detail here.

Hi everyone, could some explain please why this regex isn’t satisfactory?
It passes all tests except these two:

BadUs3rnam3 (matches but shouldn’t)
Z97 (matches but shouldn’t)

I would seem that, this is because my regex allows somehow numbers to be inserted in the middle of the string, but shouldn’t my regex prevent exactly this with the phrase
[a-z]+
?

Why is it allowing non-letters in the middle?

Thanks!

Your code so far

let username = "JackOfAllTrades";
// let userCheck = /^[a-z][a-z]+[\w]*$/i; 
let result = userCheck.test(username);

//\w - only alphanumeric
//\d*$  OR ^[^0-9]
//i

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Regular Expressions - Restrict Possible Usernames

Link to the challenge:

not sure why does it match z97
it matches ’ BadUs3rnam3’ because of ‘\w’ according to w3school
"The \w metacharacter matches word characters.

A word character is a character a-z, A-Z, 0-9, including _ (underscore)."

try to use () read:

so in the case ‘Jo’ will match but not ‘Z97’

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