UsernameValidator class
UsernameValidator extends TranslatedValidator to validate if a string meets specified username requirements.
This validator checks the username for minimum length, maximum length, and the presence or absence of numbers, underscores, dots, dashes, spaces, and special characters based on the provided constraints.
Parameters:
- minLength The minimum length of the username. Defaults to 3.
- maxLength The maximum length of the username. Defaults to 32.
- allowNumbers Whether to allow numbers in the username. Defaults to true.
- allowUnderscore Whether to allow underscores in the username. Defaults to false.
- allowDots Whether to allow dots in the username. Defaults to false.
- allowDash Whether to allow dashes in the username. Defaults to false.
- allowSpace Whether to allow spaces in the username. Defaults to false.
- allowSpecialChar Whether to allow special characters in the username. Defaults to false.
- errorText The error message returned if the validation fails.
- checkNullOrEmpty Whether to check if the value is null or empty.
- Inheritance
-
- Object
- BaseValidator<
String> - TranslatedValidator<
String> - UsernameValidator
Constructors
- UsernameValidator.new({int minLength = 3, int maxLength = 32, bool allowNumbers = true, bool allowUnderscore = false, bool allowDots = false, bool allowDash = false, bool allowSpace = false, bool allowSpecialChar = false, String? errorText, bool checkNullOrEmpty = true})
-
Constructor for the username validator.
const
Properties
- allowDash → bool
-
Whether to allow dashes in the username.
final
- allowDots → bool
-
Whether to allow dots in the username.
final
- allowNumbers → bool
-
Whether to allow numbers in the username.
final
- allowSpace → bool
-
Whether to allow spaces in the username.
final
- allowSpecialChar → bool
-
Whether to allow special characters in the username.
final
- allowUnderscore → bool
-
Whether to allow underscores in the username.
final
- checkNullOrEmpty → bool
-
Whether to check if the value is null or empty.
finalinherited
- errorText → String
-
The error message returned if the value is invalid.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxLength → int
-
The maximum length of the username.
final
- minLength → int
-
The minimum length of the username.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- translatedErrorText → String
-
The translated error message returned if the value is invalid.
no setteroverride
Methods
-
isNullOrEmpty(
String? valueCandidate) → bool -
Checks if the value is null or empty.
Returns
true
if the value is null or empty, otherwisefalse
. The value is considered empty if it is a String, Iterable, or Map and it is empty or contains only whitespace characters. If the value is not a String, Iterable, or Map, it is considered empty if it isnull
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
String? valueCandidate) → String? -
Validates the value and checks if it is null or empty.
inherited
-
validateValue(
String valueCandidate) → String? -
Validates the value.
Returns
null
if the value is valid, otherwise an error message. Call validate() instead of this method when using the validator.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited