flutter-form-builder-ecosystem / flutter-form-builder-ecosystem/form_builder_validators
SelectLengthValidator
- Dominant language
- Dart
- Stars
- 67
- Forks
- 106
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 1
Description
### Is there an existing issue for this?
- [x] 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 extends TranslatedValidator {
final Set 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;
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.