-
|
Is there a way to make a field optional, but if it is set, then it must be at least 8 chars long? I tried Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Does import { z } from "./index";
const maybeShortStr = z.string().min(5).or(z.undefined());
console.log(maybeShortStr.safeParse(undefined));
console.log(maybeShortStr.safeParse("1234"));
console.log(maybeShortStr.safeParse("12345")); |
Beta Was this translation helpful? Give feedback.
-
|
As more as I think about it, |
Beta Was this translation helpful? Give feedback.
As more as I think about it,
z.string().min(8).max(100).or(z.string().max(0))seems to be completely ok andoptionalis not the correct way to do this. I also closed the issue.