Skip to content

Commit

Permalink
Merge pull request #115 from flutter-form-builder-ecosystem/114-fix-u…
Browse files Browse the repository at this point in the history
…sername-validator

fix: remove numbers from special chars on username validator
  • Loading branch information
deandreamatias authored Jul 13, 2024
2 parents 0f078c5 + 671709f commit 93d6fb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/identity/username_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class UsernameValidator extends BaseValidator<String> {
}

if (!allowSpecialChar &&
RegExp(r'[!@#<>?":_`~;[\]\\|=+)(*&^%0-9-]').hasMatch(valueCandidate)) {
RegExp(r'[!@#<>?":_`~;[\]\\|=+)(*&^%-]').hasMatch(valueCandidate)) {
return errorText != FormBuilderLocalizations.current.usernameErrorText
? errorText
: FormBuilderLocalizations
Expand Down
16 changes: 16 additions & 0 deletions test/src/identity/username_validator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,21 @@ void main() {
// Assert
expect(result, FormBuilderLocalizations.current.usernameErrorText);
});
test('should return null if the username meets all customized requirements',
() {
// Arrange
const UsernameValidator validator = UsernameValidator(
minLength: 4,
maxLength: 15,
allowNumbers: true,
);
const String validUsername = 'abc1';

// Act
final String? result = validator.validate(validUsername);

// Assert
expect(result, isNull);
});
});
}

0 comments on commit 93d6fb2

Please sign in to comment.