by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Emir Ribić
@ribice
it fails if I don't send the field
Emir Ribić
@ribice
i mean min:1
Dean Karn
@deankarn
@ribice have you tried omitempty,min=1?
Emir Ribić
@ribice
No, I did it manually at that time (e.g. < 1)
Dean Karn
@deankarn
If you use
The validation I mention, that should work for your case
Ryan King
@ryanking
how do i get FieldError Namespace() to take into account json tag names? some of the docs make it sound like that should be happening, but it doesn't seem to be working for me
Dean Karn
@deankarn
Have you registered a tagNameFunc? That's OST likely why it wouldn't
*most likely
Ryan King
@ryanking
@joeybloggs oh I thought it would pick up names from the json tags already?
Dean Karn
@deankarn
it used to in an older version, but defining your own allows for much more flexible parsing of names, even from tags other than JSON
Ryan King
@ryanking
ah ok that makes sense
emurmotol
@emurmotol
how to validate big ints?
Value *big.Int json:"value" binding:"required,min=1000000000000000" // does not work
Franklin Harding
@fharding1
Hello! I just created this PR to add excludesfield and containsfield baked-in validators: go-playground/validator#424.
Pomke
@pomke
Hiya, sorry if this is a bit of a newbie question, I have a struct:
type LoginProvider struct {
Email string json:"email"
Phone string json:"phone"
Password string json:"password"
}
I want to validate XOR email and Phone
ie: you must provide either Email or Phone, but not both
Dean Karn
@deankarn
@pomke Once getting that specific I recommend either creating your own custom validation or creations a struct level validation.
Pomke
@pomke
Ok thank you ^_^
Devi
@asldevi
Hi, how can one inject something from application in the custom validation functions ?
Dean Karn
@deankarn
@asldevi You can Register a validation function that accepts context.Context and then use one of the validation functions that accept it eg. validate.StructCtx, but that's if it's dynamic, if looking to embed static logic from the application see here for an example go-playground/validator#462
Devi
@asldevi
thanks @deankarn
Emir Ribić
@ribice
Is this still active
:D
Dean Karn
@deankarn
yes
PhamDuykhang
@PhamDuykhang
Which tag can use for validate a string, i want to validate wich to string "times" and "Money"
Dean Karn
@deankarn

Documentation can be found here with all tags https://godoc.org/gopkg.in/go-playground/validator.v9

At present there is no built in "Money" nor "times" validator due to different locales having to validate differently, but you can create your own validations :)

Just NON
@ivybridge-3c33
I would like to check file upload is matching mime types or file extension, please help
example use :
type Photo struct { 
   Photo string `validate:"mimes=jpeg|bmp|png"`
}
Vaibhav Kumar Chaudhary
@vaibhavkumar049
how to write validate if value can be oneof or nil (not required)?
Roman
@NoMoMoRi_twitter
Hi.
How can i pass additional parameters to the custom validation function?
validator.RegisterValidation("MY_CUSTOM_TAG", MY_CUSTOM_FUNCTION)
Function only accepts validator.FieldLevel
Himanshu
@Himansh70683396_twitter
Can you please help me , I want to implement regex to multiple fields in struct, how can i do that using this package
Himanshu
@Himansh70683396_twitter
@deankarn can u please help me in this
Brandon Lee
@leejh903
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?
Harinishree-Muniraj
@Harinishree-Muniraj
Hi everyone
is there anyone having idea about cel-go package
I need to create a custom object using cel-go package
Harinishree-Muniraj
@Harinishree-Muniraj
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
error
Narsimham Chelluri
@nchelluri
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
@nchelluri
I think I prefer my handwritten validation function
Dean Karn
@deankarn
@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
@nchelluri
thank you
Nigel Li
@nigelis
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?
andig
@andig
#664 has just been added complete with tests. Would be great addition to merge this