Validator: How can i validate the slice or map? Can you please guide me?

Created on 12 Sep 2017  ·  4Comments  ·  Source: go-playground/validator

Package version eg. v8, v9:

Issue, Question or Enhancement:

Code sample, to showcase or reproduce:


question

Most helpful comment

Nice, it works great.

So fast to answer, great answers, nice library!

Thank you!

All 4 comments

Hey @anam-digicom you would need to use the dive tag documented here

basic example:

type User struct {
  Foo []string `validate"required,dive,ne=bar"`
}

let me know if that helps.

Hey @joeybloggs

This works with a struct containing a slice field, but how to validate a slice using validate.Struct(mySliceOfStructs) ?

Thanks!

@denouche because your validating a variable at this point you would use validate.Var(mySliceOfStructs, “required,dive”) or if not required use “omitempty,dive”

Nice, it works great.

So fast to answer, great answers, nice library!

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gwan284 picture gwan284  ·  4Comments

AlexMain picture AlexMain  ·  3Comments

phenrigomes picture phenrigomes  ·  5Comments

0505gonzalez picture 0505gonzalez  ·  3Comments

timakin picture timakin  ·  3Comments