"Regular Expressions: Restrict Possible Usernames"

Tell us what’s happening:
how do you make so it can be true and false when entering the last one ([a-z]|\d)+$ ?

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Restrict Possible Usernames

Link to the challenge:

Hey,
The best way is to go conditioning with the pipe | .
As well?
/(^[A-Za-z] {2,}$)|(^[A- ... /
That way you will work with each match that is given in the question but remembering there must be at least 2 letters.

1 Like

Why does it get false when I write in this

 let username = "JackOfAllTrades";
let userCheck = /(^[a-zA-Z] {2,})|(^[a-zA-Z]+\d$)/; // Change this line
let result = userCheck.test(username);
console.log(result)

When I only have /(^[A-Za-z] {2,}$)/ it’s true?
I don’t know what happend but after writing in the or statement it turned in to false. and now tested it again and can’t get true?

found out why it turned in to false.
It was the space that turned it in to false.

Found the solution now thank you! :grinning:

1 Like

Please what does the {2,} mean?

1 Like

It means 2 or more of letters/numbers/other symbols

example:
12 = true
12090429889 = true
a = false
aa = true
1_2 = true
Fish_And_Chips = true

the challenge comes after this one.