validate
Validates a value against a set of validation rules.
This function applies all the provided validation rules to the given value and collects any validation error messages. If all rules pass, it returns ValidationResult.Valid. If any rules fail, it returns a ValidationResult.Invalid containing all the error messages.
Usage:
val rules = rules<String> {
notBlank { "Required" }
minLength(3) { "Too short" }
}
val result = validate("ab", rules)
// ValidationResult.Invalid.messages will contain ["Too short"]
Content copied to clipboard
Return
A ValidationResult.Invalid containing any validation error messages, or ValidationResult.Valid if validation passes.
Parameters
V
The type of the value being validated.
value
The value to validate.
rules
The set of validation rules to apply.