Skip to content

min() together with optional() #554

@medihack

Description

@medihack

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions