Hello all, newbie here.
After hours of research and trying different things I finally came up with an acceptable solution.
My progress really sped up once I saw someone suggesting this tool – https://www.regexpal.com/
For anyone struggling I really suggest it!
Does anyone have any feedback on my code? Any suggestions on how it could improve or anything that seems redundant?
let userCheck = /^[a-zA-Z]+([a-zA-Z]|\d{2,}?)$/i; // Change this line
Thanks!
The link looks cool
the code 2
let userCheck = /^[a-zA-Z]+([a-zA-Z]|\d{2,}?)$/i; // Change this line
but what is it suppose to do?
Oops ---- I didn’t link properly to the problem.
Restrict Possible Usernames
Solutions
Solution 1 (Click to Show/Hide) let username = "JackOfAllTrades";
let userCheck = /^[a-z][a-z]+\d*$|^[a-z]\d\d+$/i;
let result = userCheck.test(username);
console.log(result)
<a name="code-explanation-3" class="anchor" href="#code-explanation-3"></a>Code Explanation
^ - start of input
[a-z] - first character is a letter
[a-z]+ - following characters are letters
\d*$ - input ends with 0 or more dig…
This regex will fail to validate usernames ending with just a single digit, like, mikemaer2. The ?
doesn’t serve any purpose too – since we’re using the $
anchor, the digits match can never be lazy.
Mike, I’m sure you’ve moved much further ahead on FCC; this is just for any newbies checking the forum for different solutions to this exercise.