Regular Expressions 101

Community Patterns

Exercise for FreeCodeCamp - Restrict Possible Usernames

0

Regular Expression
ECMAScript (JavaScript)

/
(^[a-zA-Z]{2,}\d*$|^[a-zA-Z]{1,}\d{2,}$)
/
m

Description

Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites.

You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.

Usernames can only use alpha-numeric characters.

The only numbers in the username have to be at the end. There can be zero or more of them at the end. Username cannot start with the number.

Username letters can be lowercase and uppercase.

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

Change the regex userCheck to fit the constraints listed above.

Submitted by juanalbglz - 2 years ago