Validator: How to check optional enclosed param

Created on 3 Nov 2017  Â·  3Comments  Â·  Source: go-playground/validator

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

Question

Code sample, to showcase or reproduce:


All hi, I want to validate the enclosed optional parameter how I can make it?
I have a field arr [1,2, 3] - this parameter not obligatory, and I need to check enclosure in this massif, but this massif not obligatory, now after dock I can make only this way: validate: "required, dive, required"' and the field arr obligatory has to be, and at me on a task not obligatory how to make check on enclosure without check on presence of the field?

question

Most helpful comment

Hey @AlexMain

If I understand you correctly, you only want to validate the array if it’s present.
I think you’re looking for validate:”omitempty,dive,required”

Please let me know if this is what you’re looking for :)

All 3 comments

Hey @AlexMain

If I understand you correctly, you only want to validate the array if it’s present.
I think you’re looking for validate:”omitempty,dive,required”

Please let me know if this is what you’re looking for :)

Thanks, it's work.

helpful tip :) I think it will be great if you can add it to the docs

Was this page helpful?
0 / 5 - 0 ratings