Starting of a username

Tell us what’s happening:
How to check if a username starts with a character ?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /^[a-z] \w\d$/gi; // 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/70.0.3538.110 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames

You’re on the right track, the ^[a-z] searches for an alphabet at the beginning of the username, now you have to satisfy the condition of the username being atleast 2 characters long. You can do this by using a range quantifier.
After this you have made three minor mistakes which causes your regex expression to match for a three character username or snippet of the username which starts with one alphabet, followed by a character from the \w subset and ending with a character from the \d subset.
I have written the correct answer below but I highly encourage you to try and figure out your mistakes from the hints (emphasized in bold) given above and use the answer only as your last resort.

The correct regex express is ‘let userCheck = /^[a-z]{2,}\w*[0-9]/i;’
This is because the regex matches in the order in which the terms appear, ‘^[a-z]{2,}’ matches for 2 or more alphabets appearing at the start of the username while your regex only matches for one alphabet at the beginning, '\w
’ matches for zero or more characters of the set \w while your regex only matches for one character of \w set, and ‘[0-9]’ matches for zero or more numbers appearing at the end of the username while your regex matches for one character from \d set at the end of the username.
In addition, the ‘g’ flag is not needed as we only need one solid match, or rather it is counter productive as we are using .test()

Hope this helps.