Validator: Validate a list of values

Created on 30 May 2018  路  1Comment  路  Source: go-playground/validator

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

Question

Code sample, to showcase or reproduce:

Is there an easy way to specify a list of valid values?

E.g. valid values are _us,uk,fr,mv,es,de,be_

type Request struct {
    Country       string     validate:"required,oneof=us,uk,fr,mv,es,de,be"` 
}

Most helpful comment

Ignore my question.
I just noticed there is oneof tag already (I missed it in documentation first 29 times)

So, valid code for previous example would be:

type Request struct {
    Country       string     `validate:"required,oneof=us uk fr mv es de be"` 
}

>All comments

Ignore my question.
I just noticed there is oneof tag already (I missed it in documentation first 29 times)

So, valid code for previous example would be:

type Request struct {
    Country       string     `validate:"required,oneof=us uk fr mv es de be"` 
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

puellanivis picture puellanivis  路  5Comments

ivybridge-3c33 picture ivybridge-3c33  路  3Comments

thaonx picture thaonx  路  3Comments

muhammadkholidb picture muhammadkholidb  路  3Comments

romangithub1024 picture romangithub1024  路  5Comments