I would like to make a field optional, but if it is set, then it must be at least 8 chars long. I tried z.string().min(8).optional() (which seems to be typed valid in contrast to z.string().optional().min(3)). Unfortunately, it still requires the field to be set (with at least 8 chars) and the optional is ignored.
A possible workaround seems to be z.string().min(8).max(100).or(z.string().max(0)), but it looks quite ugly.
Originally posted by @medihack in #553
I would like to make a field optional, but if it is set, then it must be at least 8 chars long. I tried
z.string().min(8).optional()(which seems to be typed valid in contrast toz.string().optional().min(3)). Unfortunately, it still requires the field to be set (with at least 8 chars) and theoptionalis ignored.A possible workaround seems to be
z.string().min(8).max(100).or(z.string().max(0)), but it looks quite ugly.Originally posted by @medihack in #553