govalidator
govalidator copied to clipboard
[Go] Package of validators and sanitizers for strings, numerics, slices and structs
Hi, Quite often structs are loaded from json using the standard json go functionality, i.e a struct definition below is quite common: ``` type User struct { FirstName string `json:"first_name"...
Hi, I have a case where govalidator does not check a tag on of a nested struct:  where Owner ID of both...
I wanna validate the slice length to use govalidator as a JSON schema checker. JSON schema has maxItems and minItems validator. http://json-schema.org/latest/json-schema-validation.html#anchor42 Isn't it usual case to check the length...
Hi. Any path having blank will fail the regex test, e.g., "/home/vux/Downloads/test something/". ``` WinPath string = `^[a-zA-Z]:\\(?:[^\\/:*?"|\r\n]+\\)*[^\\/:*?"|\r\n]*$` UnixPath string = `^((?:\/[a-zA-Z0-9\.\:]+(?:_[a-zA-Z0-9\:\.]+)*(?:\-[\:a-zA-Z0-9\.]+)*)+\/?)$` ```
When validating a US phone number with a regexp, an validation error is returned: ``` 555-234-1234 does not validate as matches(^(1-)?[2-9]{3}-[0-9]{3}-[0-9]{4}$) ``` However, this regex should match, according to https://play.golang.org/p/G_sqSKwlNw....
After some debugging I discovered a misspelling of a Govalidator struct tag in my code, i.e. ``` go type Person struct { Name string `valid:"aalpha"` } bob := Person{ Name:...
e.g. govalidator.CustomTypeTagMessageMap.Set("required", "Can't be blank") All column tagged as "required", will show "Can't be blank" if invalid. So you don't need to use `required~Can't be blank` anywhere.
Having this struct ``` type BasicInfo struct { FirstName string `json:"first_name,omitempty" db:"first_name" valid:"alpha,required"` LastName string `json:"last_name,omitempty" db:"last_name" valid:"alpha,required"` Gender int `json:"gender" db:"gender" valid:"int,required"` } ``` When i pass an int...
Hi, Is it possible to set validation on a particular field dynamically. I.e. not by using tags? One problem I have is I want to validate my ID field but...
``` if ok, err := govalidator.ValidateStruct(user); err != nil { st := reflect.TypeOf(err) fmt.Println(st) // result: govalidator.Errors type fmt.Println(st.MethodByName("Errors")) // result: {Errors func(govalidator.Errors) []error 1} true err.Errors() // result: err.Errors...