diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames/index.md index 7fb9bdeec4..d8cb7b846c 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames/index.md @@ -6,21 +6,15 @@ title: Restrict Possible Usernames ## Solution: ```javascript let username = "JackOfAllTrades"; -let userCheck = /^[a-z]{2,}\d*$/i; +const userCheck = /^[a-z]([0-9]{2,}|[a-z]+\d*)$/i; let result = userCheck.test(username); ``` ## Explain: -1. The only numbers in the username have to be at the end. `\d$` - There can be zero or more of them at the end. `*` -```javascript -/\d*$/; -``` -2. Username letters can be lowercase and uppercase. `i` -```javascript -/\d*$/i; -``` -3. Usernames have to be at least two characters long. `{2,}` - A two-letter username can only use alphabet letter characters. `^[a-z]` -```javascript -/^[a-z]{2,}\d*$/i; -``` +1. `^` - start of input +2. `[a-z]` - first character is a letter +3. `[0-9]{2,0}` - ends with two or more numbers +4. `|` - or +5. `[a-z]+` - has one or more letters next +6. `\d*` - and ends with zero or more numbers +7. `$` - end of input +8. `i` - ignore case of input