Skip to content

Commit 93d6fb2

Browse files
Merge pull request #115 from flutter-form-builder-ecosystem/114-fix-username-validator
fix: remove numbers from special chars on username validator
2 parents 0f078c5 + 671709f commit 93d6fb2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/src/identity/username_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class UsernameValidator extends BaseValidator<String> {
116116
}
117117

118118
if (!allowSpecialChar &&
119-
RegExp(r'[!@#<>?":_`~;[\]\\|=+)(*&^%0-9-]').hasMatch(valueCandidate)) {
119+
RegExp(r'[!@#<>?":_`~;[\]\\|=+)(*&^%-]').hasMatch(valueCandidate)) {
120120
return errorText != FormBuilderLocalizations.current.usernameErrorText
121121
? errorText
122122
: FormBuilderLocalizations

test/src/identity/username_validator_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,21 @@ void main() {
388388
// Assert
389389
expect(result, FormBuilderLocalizations.current.usernameErrorText);
390390
});
391+
test('should return null if the username meets all customized requirements',
392+
() {
393+
// Arrange
394+
const UsernameValidator validator = UsernameValidator(
395+
minLength: 4,
396+
maxLength: 15,
397+
allowNumbers: true,
398+
);
399+
const String validUsername = 'abc1';
400+
401+
// Act
402+
final String? result = validator.validate(validUsername);
403+
404+
// Assert
405+
expect(result, isNull);
406+
});
391407
});
392408
}

0 commit comments

Comments
 (0)