Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
Function only accepts validator.FieldLevel
Can you please help me , I want to implement regex to multiple fields in struct, how can i do that using this package
@deankarn can u please help me in this
Brandon Lee
Hi, I want to use 'hexadecimal' tag to check correct hex string. But we get value which starts with '0x'. But 'hexadecimal' tag do not accept '0x'. Do I need to create custom validator?
Hi everyone
is there anyone having idea about cel-go package
I need to create a custom object using cel-go package
while i am tryong to run cel-go package file using go run filename.go
I am getting go run: cannot run non-main package
Narsimham Chelluri
hi, I'm using gin-gonic and wondering whether I should be using go-playground/validator or my own custom validation func that operates on a model struct. are there any recommendations here? It seems like this repo would do the same thing, but then I'd have to come up with error messages to display to the user
Narsimham Chelluri
I think I prefer my handwritten validation function
Dean Karn
@nchelluri It’s really up to you and your use case, I think any of the options would work well for you. This package is geared towards rapid application development and code maintainability but ultimately how you use is up to you :)
Narsimham Chelluri
thank you
Nigel Li
Hi, when I use omitempty as the second tag for a string pointer field, the program panic.
Here is the issue go-playground/validator#654
Here is the PR go-playground/validator#657
Would anyone like to help me with this issue, or correct my usage?
#664 has just been added complete with tests. Would be great addition to merge this
Arjun Mahishi
hey guys.. I get this as the output when I try to go get this package
 $ go get github.com/go-playground/validator/v10
cannot find package "github.com/go-playground/validator/v10" in any of:
    /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT)
    /home/arjunmahishi/go/src/github.com/go-playground/validator/v10 (from $GOPATH)
But it's working when I do go get github.com/go-playground/validator
(without the v10)
ahmar siddiqui
Hello guys
thanks for creating such a robust validator I'm a go-lang noob and yet I can use it efficiently
had a query regarding validating enum types
is it possible to validate ?

Hello, I'm new to this library and have a question on validation for specific strings.

Which way is good to validate specific string such as some status string defined like this ?

I need to apply the same type validation to multiple places.

const (
    StatusSuccess = "success"
    StatusFail = "fail"
    StatusProcessing = "processing"

var validStatusList = []string{

I found 2 ways to do it using struct tag or custom validation.
I'm wondering costome valiation is better for the case we would like to use variables for validation in my current understanding because in struct tag way like the following, the strings needd to be hardcoded in struct tag.

type SomeStruct struct {
    status string `form:"status" json:"status" binding:"required,oneof=success fail processing"`
Dean Karn

@koifish082_twitter I recommend using a custom validation since you've stated you'll want to use it in multiple places.

I would use a map with the keys being your enum values and value of bool and then can us that map directly in your custom validations rule

Phani Rithvij
Hi, I have a few questions
  1. Is there a way to specify and/or constraints i.e. can be a valid email or phone no?
  2. Negations? I need a value that should not be a valid email but should be a valid alphanum
If not alphanum then alphanumunicode
Phani Rithvij
I settled with this finally validate:"alphanumunicode,excludesall=!@#$%^&*()"
ahmar siddiqui
trying to apply custom validation on *multipart.FileHeader seems to be not working ¯_(⊙︿⊙)_/¯
ex: Logo *multipart.FileHeaderform:"logo" json:"logo" binding:"filetype" gorm:"-"
Vlad Suciu
Is there a way to get a simpler error message? My messages appear as "Error:Field validation for 'Title' failed on the 'required' tag" however, if i check translations/en.go i see some friendlier messages for e.g. for required "RequiredString is a required field". Without the "tag" wording.
I have add an issure go-playground/validator#707 and fixed it with pr go-playground/validator#709
Hi everyone. I use v10. I get panic when validation tags of slice contain dive and unique. I get a panic if dive stays before unique, if dive stays after It is working correctly. Could u explain me why?
hi everyone im encountering an issue which im unable to resolve and would be happy to get hlp from the community.
im trying to dep ensure the validator/v10 and i get the folowing errs : Solving failure: No versions of github.com/go-playground/validator met constraints:
v10.4.1: Could not introduce github.com/go-playground/validator@v10.4.1, as its subpackage github.com/go-playground/validator/v10 is missing. (Package is required by (root).)
how to add validate json
pls help me show example how add validate before save in db ?
Gautam Sathe
Hello everyone!
Can someone please point me to a guide on how to use containsany? Thanks
@lnelectronic Screenshots are neither easy to read nor very accessible for many people. Please consider copying code, errors, or command output into the Go Playground, or a GitHub Gist
Hi, required_if works very well and so does required_unless. But i need something that if field A is equal to "abcd", then B should definitely be not there. required_unless is like field B is not required but can still be there.
How to do something like this? To mandatory omit a field if some field has value equal to something.
hi there I've got a question with validator json tag. problem is to validate or limit a string that only contains alpha letters or _ any ideas?
Narsimham Chelluri
Hi, I'm wondering if it is possible to do any processing of field values using validator. I'm trying to do some simple processing of data before I validate it: e.g. uppercase it, or run some custom function on it.
or is this the wrong place for that?
Dean Karn

@narsimham_twitter validator does not support modification of variables during validation. This is something that has been asked before and it is something that will not be added.

However, you are in luck, there are a number of existing packages that do exactly what you're looking for including validators companion package https://github.com/go-playground/mold

I use this package, the moddifiers portion eg. moddifiers.New() just prior to running my validation.

2 replies
Hello everyone, I have a question about the unique tag on a slice of structs. I don't known if I am doing something wrong, but I don't manage to get it working (i am using validator v10 & go v1.17.2). Am I doing something wrong ?
type Crowd struct {
    persons []Person `validate:"unique=Age"`

type Person struct {
    Name string
    Age  int

func main() {
    crowd := Crowd{persons: []Person{{"Jean", 12}, {"Anna", 12}, {"Jean", 25}}}
    v := validator.New()
    fmt.Println(v.Struct(crowd))             // should not be nil as Jean and Anna are 12 years old
    fmt.Println(v.Var(crowd, "unique=Name")) // should not be nil as there are two Jeans