Can someone please explain the difference between these? I have 3 different ways of writing the regex for this problem that in my mind should all work, but only one of them works and I don’t understand why.
Your code so far
let username = "BadUs3rnam3"; // should return false.
let userCheck = /[a-z]{2}|^[a-z][a-z]+\d*$|^[a-z]\d{2,}$/i; // returns true.
//let userCheck = /[a-z]{2}|^[a-z]([a-z]+\d*$|\d{2,})$/i; // returns true.
//let userCheck = /^[a-z]([0-9]{2,}|[a-z]+\d*)$/i; // returns false.
let result = userCheck.test(username);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12739.111.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36.
Challenge: Restrict Possible Usernames
Link to the challenge: