Tell us what’s happening:
please explain the userCheck line. Please. why the or is being used? and whats with the braces?

Your code so far

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

Your browser information:

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

Challenge: Restrict Possible Usernames

Link to the challenge:

The userCheck is a regular expression. It is being used to check the requirements of the username.
The braces are for repetition.

I hope maybe this can help you or anyone else reading:

The brackets are character sets, which can be sets of letters or numbers, among other things. [a-z] = every letter of the alphabet lowercase, [a-zA-Z] = every letter of the alphabet caps and lowercase.

/^[a-z]([0-9]{2,}|[a-z]+\d*)$/i can be broken down like:

^ = starts with
[a-z] = any letter a through z (lowercase)
()$ = ends with a match to one of the following in the capturing group
[0-9]{2,} = 2 or more numbers
| = or
[a-z]+ = 1 or more letters a through z (lowercase) and
\d* = 0 or more digits
i = ignore case flag.

if we break the regex down further to very plain english:
the string must start with a letter AND end with 1 of the following: 2 or more numbers OR 1 or more letters and 0 or more numbers.

To solve the problem, it needs to be more like:

Starts with 2 or more letters and ends with 0 or more numbers OR starts with 1 or more letters and ends with 2 or more numbers. Don’t forget to keep the ignore case flag

1 Like