|
|
@ -1058,27 +1058,14 @@ Validator notes: |
|
|
|
And the best reason, you can submit a pull request and we can keep on |
|
|
|
And the best reason, you can submit a pull request and we can keep on |
|
|
|
adding to the validation library of this package! |
|
|
|
adding to the validation library of this package! |
|
|
|
|
|
|
|
|
|
|
|
Panics |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This package panics when bad input is provided, this is by design, bad code like |
|
|
|
|
|
|
|
that should not make it to production. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Test struct { |
|
|
|
|
|
|
|
TestField string `validate:"nonexistantfunction=1"` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t := &Test{ |
|
|
|
|
|
|
|
TestField: "Test" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validate.Struct(t) // this will panic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Non standard validators |
|
|
|
Non standard validators |
|
|
|
|
|
|
|
|
|
|
|
A collection of validation rules that are frequently needed but are more |
|
|
|
A collection of validation rules that are frequently needed but are more |
|
|
|
complex than the ones found in the baked in validators. |
|
|
|
complex than the ones found in the baked in validators. |
|
|
|
A non standard validator must be registered manually using any tag you like. |
|
|
|
A non standard validator must be registered manually like you would |
|
|
|
See below examples of registration and use. |
|
|
|
with your own custom validation functions. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example of registration and use: |
|
|
|
|
|
|
|
|
|
|
|
type Test struct { |
|
|
|
type Test struct { |
|
|
|
TestField string `validate:"yourtag"` |
|
|
|
TestField string `validate:"yourtag"` |
|
|
@ -1089,7 +1076,9 @@ See below examples of registration and use. |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
validate := validator.New() |
|
|
|
validate := validator.New() |
|
|
|
validate.RegisterValidation("yourtag", validations.ValidatorName) |
|
|
|
validate.RegisterValidation("yourtag", validators.NotBlank) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Here is a list of the current non standard validators: |
|
|
|
|
|
|
|
|
|
|
|
NotBlank |
|
|
|
NotBlank |
|
|
|
This validates that the value is not blank or with length zero. |
|
|
|
This validates that the value is not blank or with length zero. |
|
|
@ -1097,5 +1086,20 @@ See below examples of registration and use. |
|
|
|
ensures they don't have zero length. For others, a non empty value is required. |
|
|
|
ensures they don't have zero length. For others, a non empty value is required. |
|
|
|
|
|
|
|
|
|
|
|
Usage: notblank |
|
|
|
Usage: notblank |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Panics |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This package panics when bad input is provided, this is by design, bad code like |
|
|
|
|
|
|
|
that should not make it to production. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Test struct { |
|
|
|
|
|
|
|
TestField string `validate:"nonexistantfunction=1"` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t := &Test{ |
|
|
|
|
|
|
|
TestField: "Test" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validate.Struct(t) // this will panic
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package validator |
|
|
|
package validator |
|
|
|