Last active
July 14, 2023 12:42
-
-
Save RTAndrew/a9d26f70f05eca7abcf77ef5bc612fd7 to your computer and use it in GitHub Desktop.
Revisions
-
RTAndrew revised this gist
Jul 14, 2023 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,11 +19,8 @@ export const validateDiscordUsername = (username: string) => { const _containsSpecialChars = new RegExp('[^A-Za-z0-9_.]').test(username); if (username.length < 2 || username.length > 32) breaksMinMaxLength = true; if (_hasSuccessiveDots) hasSuccessiveDots = true; if (_isCaseSensitive) isCaseSensitive = true; if (_containsSpecialChars) containsSpecialChars = true; return { hasSuccessiveDots, isCaseSensitive, containsSpecialChars, breaksMinMaxLength }; -
RTAndrew renamed this gist
Jul 14, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
RTAndrew created this gist
Jul 14, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ /** * Validate Discord username according to the services's rules * @param username the user's username * @returns ```{ hasSuccessiveDots, isCaseSensitive, containsSpecialChars, breaksMinMaxLength }``` * @summary It does not support the previews version: discordUSerName#1234 * @see https://support.discord.com/hc/en-us/articles/12620128861463-New-Usernames-Display-Names */ export const validateDiscordUsername = (username: string) => { // The RegEx support this validation: // ^(?!.*[.]{2,})[a-zA-Z0-9_.]{2,32}$ let hasSuccessiveDots = false; let isCaseSensitive = false; let containsSpecialChars = false; let breaksMinMaxLength = false; const _hasSuccessiveDots = new RegExp('^.*[.]{2,}$').test(username); const _isCaseSensitive = new RegExp('[A-Z]+').test(username); const _containsSpecialChars = new RegExp('[^A-Za-z0-9_.]').test(username); if (username.length < 2 || username.length > 32) breaksMinMaxLength = true; if (_hasSuccessiveDots) hasSuccessiveDots = true; if (_isCaseSensitive) isCaseSensitive = true; if (_containsSpecialChars) containsSpecialChars = true; return { hasSuccessiveDots, isCaseSensitive, containsSpecialChars, breaksMinMaxLength }; };