Tell us what’s happening:
these were the instructions for the regex problem:
You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.
- Usernames can only use alpha-numeric characters.
- The only numbers in the username have to be at the end. There can be zero or more of them at the end. Username cannot start with the number.
- Username letters can be lowercase and uppercase.
- Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.
Kindly help me understand why this is wrong with my solution. (i have written the comments below the code)
Your code so far
let username = "JackOfAllTrades"; let userCheck = /^[a-z][a-z]+\d*$|^[a-z]\d\d+$/gi; // Change this line let result = userCheck.test(username); console.log(result); /* ^[a-z][a-z]+ : first two characters should be at least two alphabet letters and optional number(s) at the end | : or ^[a-z]\d\d+$ : first letter is an alphabet followed by at least 2 numeric characters whereby the last character is a digit */
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Challenge: Restrict Possible Usernames
Link to the challenge: