Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Trevor Johnson
14,427 PointsJavaScript Regex Challenge
Hey there, I am doing a regex challenge on this site: https://beta.freecodecamp.com/en/challenges/regular-expressions/restrict-possible-usernames.
I have taken my regex and put it into this site and all the parameters pass: https://regex101.com/r/fqeFDT/1.
If I have made an error can someone please point it out? I am failing the 1st and 4th check on freeCodeCamp.
And here is my code:
let username = "JackOfAllTrades";
let userCheck = /^[a-z]{2}([a-z]+)?(\d+)?$/gi; // Change this line
let result = userCheck.test(username);

Trevor Johnson
14,427 PointsI'll restart, but do you have any idea why it seems to work fine on regex101.com? It passes all the parameters there.
1 Answer

Konrad Traczyk
22,287 PointsYour solution probably doesnt work probably because due challange interpreter limitation because it works in browser console and regex101.com. You could remove /g and you will pass it.
Konrad Traczyk
22,287 PointsKonrad Traczyk
22,287 PointsYour regex is complicated, i did this challange in 5 min. I believe the best advice here is just start over, try diffrent way, remember to keep this simple. Use regex101.com reference as guide.