Questions about Solution to "Restrict Possible Usernames" Challenge

Tell us what’s happening:

Why is it necessary to use [0-9] twice in the following solution or why is there [\d][\d]?

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 9; SM-G955U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Mobile Safari/537.36.

Challenge: Restrict Possible Usernames

Link to the challenge:

Because of this condition:

A two-character username can only use alphabet letters as characters.

This part of the regex : ^[a-z]([0-9][0-9]+ ensures if there is only one letter, there are at least two numbers following it.

1 Like
  1. Usernames have to be at least two characters long.
  2. A two-character username can only use alphabet letters as characters.

So

Your regex should not match J
Your regex should match Jo
Your regex should not match A1
Your regex should match Z97

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, 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.

Thank you.