Restrict Possible Usernames challenge says to make a regular expression for checking usernames with following rules:
- 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.
I came up with a solution and it gives correct results but I want to know if there’s a shorter one:
let username = "JackOfAllTrades";
let userCheck = /(^[a-z][a-z]+$)|(^[a-z][a-z]+\d$)|(^[a-z][a-z]*\d\d+$)/i;
let result = userCheck.test(username);