Regex username test

Tell us what’s happening:
I’ve tried many variations to this but can’t figure out how to get it done.

I am left with one item I can’t pass and that is it should not match A1, but it does.

Any tips?

Your code so far

let username = "JackofAllTrades";
let userCheck = /^\D+[\w*]\d*?$/i; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 EdgiOS/45.9.5 Mobile/15E148 Safari/605.1.15.

Challenge: Restrict Possible Usernames

Link to the challenge:

I think you should try matching words in regex101
I guess, you’ll figure it out from there

Not exactly what I’m looking for. I’ve utilized testers already and the FCC problem itself already tells me true or false.

I know my regex matches the last check (A1) but it shouldn’t which means I need to fix something. If you could provide insight into what I’m missing here that would be more helpful.

problem says that, if string contains only two characters they must be alphabets…
I think you should handle this case separately for 2 characters and separate for string with more than 2 characters…
you can use | as OR operator in regex…
I guess you also need to read this

So are you saying that I should be using {2} in my regex? Why would I be required to use a function that FCC hasn’t even taught to me yet?

That lesson doesn’t come until after the current one I’m on so there must be a way to
do it without using {}. It wouldn’t make sense to have people use that technique without teaching it first.

\D{2} is same as \D\D

I guess, you’ve solved the challenge, but still I’m pasting the solution here, if you haven’t yet


  • first ^[a-z] is there because, first character must be an alphabet…
  • next there must be atleast one alphabet([a-z]+), and any number of digits(\d*)
  • In another case for case like Z97, \d\d+ is used(Atleast 2 digits)…
    this can also be done by \d{2,}, but as you said, you’ve not reached till this, so I’ve provided alternative

I did solve it. Slightly different than that answer but got it. I didn’t realize I needed o build a second regex for that one item and OR it like you said. I also used the \D\D like you said.

you can use it

let userCheck = /^[a-zA-Z]+([a-zA-Z]|\d\d$)+\d*$/;

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

1 Like

sorry , I am new to forum , I will remember next time

Very useful info. I’ll try not to post full solution Sir.