Skip to content

validating optional field is between certain range #763

Closed
@thegalang

Description

@thegalang

Package version eg. v9, v10: v10

Issue, Question or Enhancement:

Is there a way to validate optional fields? let's say I want to validate if field str has either length 0 (not included) or length greater than 5.

Code sample, to showcase or reproduce:

Currently, I made a custom validator and tag like so:

type TestStruct {
TestStr string `validate:"optional_gte=5"`
}

So these strings will pass: "" "galang". These will fail: "ka".

Is there any way to do this built-in? if not, I can submit a PR with my custom tags if it's beneficial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions