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

Commit c42cf19

Browse files
authored
Merge pull request #531 from duichwer/fix/usernameRegex
🐛 Fix Username RegEx
2 parents b05a72e + d15f73a commit c42cf19

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/services/validation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class ValidationService {
175175
}
176176

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

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

lib/widgets/theming/smart_text.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ final _tagRegex = RegExp(r"\B#\w*[a-zA-Z]+\w*", caseSensitive: false);
9696

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

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

0 commit comments

Comments
 (0)