Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #531 from duichwer/fix/usernameRegex
Browse files Browse the repository at this point in the history
🐛 Fix Username RegEx
  • Loading branch information
lifenautjoe authored May 27, 2020
2 parents b05a72e + d15f73a commit c42cf19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/services/validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class ValidationService {
}

bool isUsernameAllowedCharacters(String username) {
String p = r'^[a-zA-Z0-9_.]+$';
String p = r'^[a-zA-Z0-9](?:[._]?[a-z-A-Z0-9])*$';

RegExp regExp = new RegExp(p, caseSensitive: false);

Expand Down
12 changes: 6 additions & 6 deletions lib/widgets/theming/smart_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ final _tagRegex = RegExp(r"\B#\w*[a-zA-Z]+\w*", caseSensitive: false);

// Architecture of this regex:
// (?: don't capture this group, so the mention itself is still the first capturing group
// [^A-Za-u0-9]|^ make sure that no word characters are in front of name
// \s|^ make sure that no word characters are in front of name
// )
// (
// @ begin of mention
// \@ begin of mention
// [A-Za-z0-9] first character of username
// (
// (
// [A-Za-z0-9]|[._-](?![._-]) word character or one of [._-] which may not be followed by another special char
// (?:
// (?:
// [A-Za-z0-9]|[._](?![._]) word character or one of [._] which may not be followed by another special char
// ){0,28} repeat this 0 to 28 times
// [A-Za-z0-9] always end on a word character
// )? entire part is optional to allow single character names
// ) end of mention
// (?=\b|$) next char must be either a word boundary or end of text
final _usernameRegex = RegExp(
r"(?:[^A-Za-u0-9]|^)(@[A-Za-z0-9](([A-Za-z0-9]|[._-](?![._-])){0,28}[A-Za-z0-9])?)(?=\b|$)",
r"(?:\s|^)(\@[A-Za-z0-9](?:(?:[A-Za-z0-9]|[._](?![._])){0,28}[A-Za-z0-9])?)(?:\b|$)",
caseSensitive: false);

// Same idea as inner part of above regex, but only _ is allowed as special character
Expand Down

0 comments on commit c42cf19

Please sign in to comment.