let username = "JackOfAllTrades";
let userCheck = /^[A-Za-z]+[A-Za-z][\d+|\d*]$/; // Change this line
let result = userCheck.test(username);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
1. Usernames can only use alphanumeric characters.
2. 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.
3. Username letters can be lowercase and uppercase.
4. Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.
You probably know that requirements 1 though 3 can be matched, easily with a single logic search. Something like
^[A-z]+[0-9]*$
However, step 4 requires alternative logic of search. (using the symbol | ) because if the length of the username is only two characters, these must be alphabet ones.
In other words. We have two alternatives:
Start with two alpha characters ^[A-z]{2, }
or start with an alpha character followed by at least two digits ^[A-z][0-9]{2, }
The format, then, all together might be similar to: