forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [torrust#503] add more contrains for usernames
Usernames will only allow the following characters: - Uppercase and lowercase letters (`A-Z`, `a-z`) - Digits (`0-9`) - The simple dash (`-`) - The underscore (`_`) Additionally, we'll enforce a maximum length of 20 characters for the usernames. We exclude emojis, blank spaces, non-valid UTF-8 characters, and non-ASCII characters ```regex ^[A-Za-z0-9-_]{1,20}$ ``` Explanation: - `^` asserts the start of the string. - `[A-Za-z0-9-]` is a character class that matches uppercase letters (`A-Z`), lowercase letters (`a-z`), digits (`0-9`), and the simple dash (`-`) or underscore (`_`). - `{1,20}` quantifier makes sure that the preceding character class matches between 1 and 20 times, inclusive, which enforces your maximum length requirement. - `$` asserts the end of the string. This regular expression ensures that usernames consist only of the specified characters and do not exceed 20 characters in length. It effectively excludes emojis, blank spaces, non-valid UTF-8 characters, and non-ASCII characters, as they are not included in the specified character set. The API endpoint `/register` for registration should return a Bad Request when the username does to match this regexp.
- Loading branch information
1 parent
0fc5518
commit 553208e
Showing
3 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters