-
-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is there an existing issue for this?
- I have searched the existing issues
Package/Plugin version
11.1.1
What you'd like to happen
Hello. I would like to suggest that you implement a length validator, with options to choose from. This may be necessary for some standardized form values, such as INN (which can be either 10 or 12 characters long).
Alternatives you've considered
Not found
Aditional information
class SelectLengthValidator<T> extends TranslatedValidator<T> {
final Set<int> lengthOptions;
const SelectLengthValidator(this.lengthOptions, {
super.errorText,
super.checkNullOrEmpty,
});
@override
String get translatedErrorText => 'The length of the value must be one of the following values: $lengthOptions.';
@override
String? validateValue(T valueCandidate) {
final valueLength = switch (valueCandidate) {
String() => valueCandidate.length,
Iterable() => valueCandidate.length,
Map() => valueCandidate.length,
_ => 0,
};
return !lengthOptions.contains(valueLength) ? errorText : null;
}
}
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
Backlog