zod
zod copied to clipboard
How make field optional but have minimal character
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