OR Operators (Or / OrElse)
Valgo supports OR-style logic inside a validator chain.
Overview
Section titled “Overview”Or(...)evaluates an alternative branch.OrElse(...)is likeOr, but lets you override the resulting message when all branches fail.
Example
Section titled “Example”Require either an email-like string or a phone-like string:
emailRe := regexp.MustCompile(`^.+@.+\..+$`)phoneRe := regexp.MustCompile(`^\+?[0-9]{7,}$`)
val := v.Is( v.String(contact, "contact"). MatchingTo(emailRe). Or(v.String(contact, "contact").MatchingTo(phoneRe)),)If you want a single consolidated error message:
val := v.Is( v.String(contact, "contact"). MatchingTo(emailRe). OrElse( v.String(contact, "contact").MatchingTo(phoneRe), "Contact must be a valid email or phone number", ),)