Hi all- I am trying to solve the exercise “Restrict Possible Usernames.” After several attempts, my code still fails one of the tests:
let userCheck = /^[a-z][a-z]+\d*$/i;
**
"Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters. "
**
The way i read my code is:
it should start with at least 2 alphabet letters
^ [a-z][a-z] +
it should end with 0 or more digits
\d*$/
it should take upper or lower case.
i
I took a look at the answers and noticed they can include a number after the first letter, but the test asks that if the username is a two-character username, we should use alphabet letters. I also tried using the global character (g) but it wouldn’t work.
Please help! what am i not seeing?
Thank you!
Your code so far
let username = "JackOfAllTrades";
//let userCheck = /\D[a-zA-Z]\d/i; // Change this line
//let userCheck = /^[a-zA-Z.+\d]/ig;
//let userCheck = /\D^[a-zA-Z.+\d]/ig;
//let userCheck = /\D[a-z+]\d*$/i;
//let userCheck = /[a-z]{2,}\d*/gi;
let userCheck = /^[a-z][a-z]+\d*$/i;
let result = userCheck.test(username);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36
Challenge: Restrict Possible Usernames
Link to the challenge: