or
condition?
#362
-
I wish to make the
For implementing (2) and (3), I used to use |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Jan 17, 2024
Replies: 2 comments 9 replies
-
OK, I guess I figered it out. const email = optional(
union(
[string([email()]), literal("")],
"Not a valid email"
)
); Note that, unlike Zod, the custom error message must associated with |
Beta Was this translation helpful? Give feedback.
9 replies
-
Note: With v0.26.0 the behavior has changed to improve the DX. The schema must now be written as follows: import * as v from 'valibot';
const EmailSchema = v.optional(
v.union([v.string([v.email('Not a valid email')]), v.literal('')])
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fabian-hiller
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: With v0.26.0 the behavior has changed to improve the DX. The schema must now be written as follows: