Constraints for Regex

Tell us what’s happening:
My regex is matching BadUs3rnam3 and c57bT3, which is not supposed to be so… Just these two remaining out of all the constraints to fit, Pls how can i work around this…

Your code so far


let username = "JackOfAllTrades";
let userCheck = /\D\w.\d*$|[a-z][a-z]/i; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173.

Challenge: Restrict Possible Usernames

Link to the challenge:

I’ll just give you hints, and a method to better test how your code is doing:

let username = "BadUs3rnam3";
let userCheck = /\D\w.\d*$/i; // Change this line
let test = userCheck.test(username);
let match = username.match(userCheck)[0]
console.log(test match)

HINTS:

  1. to match a full word you need the caret symbol.
  2. You can dismiss the |[a-z][a-z] for now. (And it can be condensed to [a-z]{2} but that’s probably further on in the curriculum.

Comment

When match finds just one match, it returns a lot of ‘metadata’, so I appended a [0] but that’s completely optional.