Restrict Possible Usernames REGEX

Restrict Possible Usernames REGEX
0

#1

Tell us what’s happening:

Your code so far


let username = "JackOfAllTrades";
let userCheck = /^[a-z]*\D[0-9]$/gi; // 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/67.0.3396.99 Safari/537.36.

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


#2

You have to make sure your regex is restricting the allowed names based on the given instructions.
For eg, you have said in the regex that the username may start with an english alphabetic character [a-z] but doesn’t have to.
This is incorrect because all usernames need at least one alphabetic character at the start. And if the name is only two letters in total length, it must consist of only alphabetic characters.

Eg. D8 is invalid but gH is valid.
If you need a place to test your regex, try www.regextester.com as it is very useful to learn how to write these.


#3

Thanks a lot. I must admit really trying to wrap my head on the Regex thingy