any method
Ensures that the value satisfies at least one of the given validators.
This method applies multiple validation rules (types
), and the value
must pass at least one of them for the validation to succeed.
Example
final validator = v.string().any([
v.string().equals('hello'),
v.string().equals('world'),
]);
print(validator.validate('hello')); // null (valid)
print(validator.validate('world')); // null (valid)
print(validator.validate('hello world')); // 'Invalid value' (invalid)
print(validator.validate('random text')); // 'Invalid value' (invalid)
Parameters
types
: A list ofVType<T>
validators, at least one of which must be satisfied.message
: (optional) A custom error message to return if validation fails.
Returns
The current VType<T>
instance with the any
validation applied.
Implementation
VType<T> any(List<VType<T>> types, {String? message}) {
return add(AnyValidator(types, message: message!));
}