Tell us what’s happening:
Any one completed this challenge…
how to check the condition of atleast two char in Regex
Your code so far
let username = "JackOfAllTrades";
let userCheck = /0-9$/i; // Change this line
let result = userCheck.test(username);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
To specify n or more of something you can use {n,}
after it
So for example if we want 4 or more of the letter a, we can use a{4,}
in our regex
1 Like
Hello, Do you remember +
? We can use it to find character that at least occur one time. So there is the answer:
let username = "JackOfAllTrades";
let userCheck = /[a-zA-Z][a-zA-Z]+[0-9]*/; // Change this line
let result = userCheck.test(username);
2 Likes
Dear @zero_loop can you explain your answer, please!
First, we use [a-zA-Z]
to make sure there is one character in the name,
then, we use [a-zA-Z]+
to make sure there is at least one character in the name,
thus, there are at least two characters in the name, right?
finally, we use [0-9]*
to find numbers.
If I express not clearly, please let me know!
2 Likes