Regular Expressions: Restrict Possible Usernames 2021

I can’t fix Z97 and Jo at a time. The more I think it’s getting messier. Can you please tell me a better way to fix it?
Please try to fix it using the previous exercises of regular expression in freeCodeCamp otherwise, add the source to study it later.

My code so far


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

Output

// running tests
Your regex should match Z97
// tests completed

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Restrict Possible Usernames

Link to the challenge:

my suggestion is to review this challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/match-a-literal-string-with-different-possibilities

2 Likes

Thank you so much. I got it after a long time :tired_face:

/^[a-z] ([a-z]+[\d]*$|.[\d][\d]*$)/i

your regex can also have something like a !56 pass, I know it’s not in the tests but maybe try to avoid that

I don’t get it. Can you please explain? :frowning:

try with a!56 like I said above

1 Like

Thank you :hugs:
Before I thought just !56 instead of a!56
I replaced .(dot) to \w to fix this.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.