zod icon indicating copy to clipboard operation
zod copied to clipboard

How make field optional but have minimal character

Open hscstudio opened this issue 9 months ago • 3 comments

I want field optional or non required but if it is not blank then it minimal 3 character, and if it is blank then permitted

I have do this

z.string().min(field.min, {
                message: `${field.label} must be at least ${field.min} characters.`,
}).optional();

But, if field empty, appear warning "must be at least 3 characters" :(

I have do with nullable, nullish but still same error

hscstudio avatar May 25 '24 12:05 hscstudio