mirror of
https://github.com/Fishwaldo/validator.git
synced 2025-03-15 19:51:38 +00:00
Rework the non standard validators documentation
This commit is contained in:
parent
cd1bd58169
commit
94aa4243a2
1 changed files with 29 additions and 25 deletions
54
doc.go
54
doc.go
|
@ -1058,6 +1058,35 @@ Validator notes:
|
|||
And the best reason, you can submit a pull request and we can keep on
|
||||
adding to the validation library of this package!
|
||||
|
||||
Non standard validators
|
||||
|
||||
A collection of validation rules that are frequently needed but are more
|
||||
complex than the ones found in the baked in validators.
|
||||
A non standard validator must be registered manually like you would
|
||||
with your own custom validation functions.
|
||||
|
||||
Example of registration and use:
|
||||
|
||||
type Test struct {
|
||||
TestField string `validate:"yourtag"`
|
||||
}
|
||||
|
||||
t := &Test{
|
||||
TestField: "Test"
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
validate.RegisterValidation("yourtag", validators.NotBlank)
|
||||
|
||||
Here is a list of the current non standard validators:
|
||||
|
||||
NotBlank
|
||||
This validates that the value is not blank or with length zero.
|
||||
For strings ensures they do not contain only spaces. For channels, maps, slices and arrays
|
||||
ensures they don't have zero length. For others, a non empty value is required.
|
||||
|
||||
Usage: notblank
|
||||
|
||||
Panics
|
||||
|
||||
This package panics when bad input is provided, this is by design, bad code like
|
||||
|
@ -1072,30 +1101,5 @@ that should not make it to production.
|
|||
}
|
||||
|
||||
validate.Struct(t) // this will panic
|
||||
|
||||
Non standard validators
|
||||
|
||||
A collection of validation rules that are frequently needed but are more
|
||||
complex than the ones found in the baked in validators.
|
||||
A non standard validator must be registered manually using any tag you like.
|
||||
See below examples of registration and use.
|
||||
|
||||
type Test struct {
|
||||
TestField string `validate:"yourtag"`
|
||||
}
|
||||
|
||||
t := &Test{
|
||||
TestField: "Test"
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
validate.RegisterValidation("yourtag", validations.ValidatorName)
|
||||
|
||||
NotBlank
|
||||
This validates that the value is not blank or with length zero.
|
||||
For strings ensures they do not contain only spaces. For channels, maps, slices and arrays
|
||||
ensures they don't have zero length. For others, a non empty value is required.
|
||||
|
||||
Usage: notblank
|
||||
*/
|
||||
package validator
|
||||
|
|
Loading…
Add table
Reference in a new issue