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.
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.
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.