Documentation ¶
Overview ¶
Package validate implements validate utility functions.
Usage
err := validate.Required("ABc123") err = validate.Min("30", 20); err = validate.Max("30", 50); err = validate.Float("1.23"); err = validate.Integer("123"); err = validate.Alphanumeric("ABc123"); err = validate.Alphabetic("ABc"); err = validate.Email("admin@goyy.org"); err = validate.URL("ftp://admin:123456@goyy.org/");
Index ¶
- func Alhan(input string) error
- func Alhanrod(input string) error
- func All(tests ...error) []error
- func Alnum(input string) error
- func Alnumhan(input string) error
- func Alnumhanrod(input string) error
- func Alnumrod(input string) error
- func Alpha(input string) error
- func Alrod(input string) error
- func Any(tests ...error) error
- func Chain(input string, links ...func(string) error) error
- func Each(tests ...error) error
- func Email(input string) error
- func Float(input string) error
- func Han(input string) error
- func Hanrod(input string) error
- func IP(input string) error
- func Integer(input string) error
- func Match(input, regexps string) error
- func Max(input string, max int) error
- func Maxf(input string, max float64) error
- func Maxlen(input string, max int) error
- func Min(input string, min int) error
- func Minf(input string, min float64) error
- func Minlen(input string, min int) error
- func Mobile(input string) error
- func Nomatch(input, regexps string) error
- func Phone(input string) error
- func Range(input string, min, max int) error
- func Rangef(input string, min, max float64) error
- func Rangelen(input string, min, max int) error
- func Required(input string) error
- func SetLocale(locale string)
- func Tel(input string) error
- func URL(input string) error
- func Zipcode(input string) error
- type Error
- type Validation
- func (me *Validation) Alhan(field, input string) *Error
- func (me *Validation) Alhanrod(field, input string) *Error
- func (me *Validation) Alnum(field, input string) *Error
- func (me *Validation) Alnumhan(field, input string) *Error
- func (me *Validation) Alnumhanrod(field, input string) *Error
- func (me *Validation) Alnumrod(field, input string) *Error
- func (me *Validation) Alpha(field, input string) *Error
- func (me *Validation) Alrod(field, input string) *Error
- func (me *Validation) Clear()
- func (me *Validation) Email(field, input string) *Error
- func (me *Validation) Float(field, input string) *Error
- func (me *Validation) Han(field, input string) *Error
- func (me *Validation) Hanrod(field, input string) *Error
- func (me *Validation) HasErrors() bool
- func (me *Validation) IP(field, input string) *Error
- func (me *Validation) Integer(field, input string) *Error
- func (me *Validation) Match(field, input, regexps string) *Error
- func (me *Validation) Max(field, input string, max int) *Error
- func (me *Validation) Maxf(field, input string, max float64) *Error
- func (me *Validation) Maxlen(field, input string, max int) *Error
- func (me *Validation) Min(field, input string, min int) *Error
- func (me *Validation) Minf(field, input string, min float64) *Error
- func (me *Validation) Minlen(field, input string, min int) *Error
- func (me *Validation) Mobile(field, input string) *Error
- func (me *Validation) Nomatch(field, input, regexps string) *Error
- func (me *Validation) Phone(field, input string) *Error
- func (me *Validation) Range(field, input string, min, max int) *Error
- func (me *Validation) Rangef(field, input string, min, max float64) *Error
- func (me *Validation) Rangelen(field, input string, min, max int) *Error
- func (me *Validation) Required(field, input string) *Error
- func (me *Validation) Tel(field, input string) *Error
- func (me *Validation) URL(field, input string) *Error
- func (me *Validation) Zipcode(field, input string) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alhan ¶
Alhan returns error if the provided input is not an alphabetic or chinese (a-zA-Z\p{Han}) string, nil otherwise.
func Alhanrod ¶
Alhanrod returns error if the provided input is not an alphabetic or chinese or rod (a-zA-Z\p{Han}\-_) string, nil otherwise.
func All ¶
All this function accepts a list of error values (from values or functions) and returns an array of errors values, useful for validating all user inputs at once.
Example:
err := validate.All(
validate.Email(userEmail), validate.Chain(userName, validate.Required),
)
func Alnum ¶
Alnum returns error if the provided input is not an alphanumeric (a-zA-Z0-9) string, nil otherwise.
func Alnumhan ¶
Alnumhan returns error if the provided input is not an alphanumeric or chinese (a-zA-Z0-9\p{Han}) string, nil otherwise.
func Alnumhanrod ¶
Alnumhanrod returns error if the provided input is not an alphanumeric or chinese or rod (a-zA-Z0-9\p{Han}\-_) string, nil otherwise.
func Alnumrod ¶
Alnumrod returns error if the provided input is not an alphanumeric or rod (a-zA-Z0-9\-_) string, nil otherwise.
func Alpha ¶
Alpha returns error if the provided input is not an alphabetic (a-zA-Z) string, nil otherwise.
func Alrod ¶
Alrod returns error if the provided input is not an alphabetic or rod (a-zA-Z\-_) string, nil otherwise.
func Any ¶
Any this function accepts a list of error values (from values or functions) and returns nil if any of the rules is valid.
Example:
err := validate.Any(
validate.Required(userAge), validate.Integer(userAge),
)
func Chain ¶
Chain this function takes an input an applies the given set of validation functions in order, each function is a link of the chain. If any validation fails, validate.Chain stops and returns the error.
Example:
err := validate.Chain(userEmail, validate.Required, validate.Email)
func Each ¶
Each this function accepts a list of error values (from values or functions) and returns the first error found, if any.
Example:
err := validate.Each(
validate.Email(userEmail), validate.Chain(userName, validate.Required),
)
func Float ¶
Float returns error if the provided input is not a floating point number, nil otherwise.
func Han ¶
Han returns error if the provided input is not an alphabetic or chinese (\p{Han}) string, nil otherwise.
func Hanrod ¶
Hanrod returns error if the provided input is not an alphabetic or chinese or rod (\p{Han}\-_) string, nil otherwise.
func Maxlen ¶
Maxlen returns error if the provided input is more than {max} characters, nil otherwise.
func Min ¶
Min returns error if the provided input is greater than or equal to {min}, nil otherwise.
func Minf ¶
Minf returns error if the provided input is greater than or equal to {min}, nil otherwise.
func Rangelen ¶
Rangelen returns error if the provided input is between {min} and {max} characters long, nil otherwise.
Types ¶
type Validation ¶
type Validation struct {
Errors []*Error
}
Validation validate.Validation.
func (*Validation) Alhan ¶
func (me *Validation) Alhan(field, input string) *Error
Alhan returns error if the provided input is not an alphabetic or chinese (a-zA-Z\p{Han}) string, nil otherwise.
func (*Validation) Alhanrod ¶
func (me *Validation) Alhanrod(field, input string) *Error
Alhanrod returns error if the provided input is not an alphabetic or chinese or rod (a-zA-Z\p{Han}\-_) string, nil otherwise.
func (*Validation) Alnum ¶
func (me *Validation) Alnum(field, input string) *Error
Alnum returns error if the provided input is not an alphanumeric (a-zA-Z0-9) string, nil otherwise.
func (*Validation) Alnumhan ¶
func (me *Validation) Alnumhan(field, input string) *Error
Alnumhan returns error if the provided input is not an alphanumeric or chinese (a-zA-Z0-9\p{Han}) string, nil otherwise.
func (*Validation) Alnumhanrod ¶
func (me *Validation) Alnumhanrod(field, input string) *Error
Alnumhanrod returns error if the provided input is not an alphanumeric or chinese or rod (a-zA-Z0-9\p{Han}\-_) string, nil otherwise.
func (*Validation) Alnumrod ¶
func (me *Validation) Alnumrod(field, input string) *Error
Alnumrod returns error if the provided input is not an alphanumeric or rod (a-zA-Z0-9\-_) string, nil otherwise.
func (*Validation) Alpha ¶
func (me *Validation) Alpha(field, input string) *Error
Alpha returns error if the provided input is not an alphabetic (a-zA-Z) string, nil otherwise.
func (*Validation) Alrod ¶
func (me *Validation) Alrod(field, input string) *Error
Alrod returns error if the provided input is not an alphabetic or rod (a-zA-Z\-_) string, nil otherwise.
func (*Validation) Email ¶
func (me *Validation) Email(field, input string) *Error
Email returns error if the provided input is not an email, nil otherwise.
func (*Validation) Float ¶
func (me *Validation) Float(field, input string) *Error
Float returns error if the provided input is not a floating point number, nil otherwise.
func (*Validation) Han ¶
func (me *Validation) Han(field, input string) *Error
Han returns error if the provided input is not an chinese (\p{Han}) string, nil otherwise.
func (*Validation) Hanrod ¶
func (me *Validation) Hanrod(field, input string) *Error
Hanrod returns error if the provided input is not an chinese or rod (\p{Han}\-_) string, nil otherwise.
func (*Validation) HasErrors ¶
func (me *Validation) HasErrors() bool
HasErrors has Validation Errors nor not.
func (*Validation) IP ¶
func (me *Validation) IP(field, input string) *Error
IP returns error if the provided input is not an IP, nil otherwise.
func (*Validation) Integer ¶
func (me *Validation) Integer(field, input string) *Error
Integer returns error if the provided input is not an integer value, nil otherwise.
func (*Validation) Match ¶
func (me *Validation) Match(field, input, regexps string) *Error
Match returns error if the provided input is not match {regexp} string, nil otherwise.
func (*Validation) Max ¶
func (me *Validation) Max(field, input string, max int) *Error
Max returns error if the provided input is less than or equal to {max}, nil otherwise.
func (*Validation) Maxf ¶
func (me *Validation) Maxf(field, input string, max float64) *Error
Maxf returns error if the provided input is less than or equal to {max}, nil otherwise.
func (*Validation) Maxlen ¶
func (me *Validation) Maxlen(field, input string, max int) *Error
Maxlen returns error if the provided input is more than {max} characters, nil otherwise.
func (*Validation) Min ¶
func (me *Validation) Min(field, input string, min int) *Error
Min returns error if the provided input is greater than or equal to {min}, nil otherwise.
func (*Validation) Minf ¶
func (me *Validation) Minf(field, input string, min float64) *Error
Minf returns error if the provided input is greater than or equal to {min}, nil otherwise.
func (*Validation) Minlen ¶
func (me *Validation) Minlen(field, input string, min int) *Error
Minlen returns error if the provided input is least {min} characters, nil otherwise.
func (*Validation) Mobile ¶
func (me *Validation) Mobile(field, input string) *Error
Mobile returns error if the provided input is not an mobile, nil otherwise.
func (*Validation) Nomatch ¶
func (me *Validation) Nomatch(field, input, regexps string) *Error
Nomatch returns error if the provided input is match {regexp} string, nil otherwise.
func (*Validation) Phone ¶
func (me *Validation) Phone(field, input string) *Error
Phone returns error if the provided input is not an phone, nil otherwise.
func (*Validation) Range ¶
func (me *Validation) Range(field, input string, min, max int) *Error
Range returns error if the provided input is between {min} and {max}, nil otherwise.
func (*Validation) Rangef ¶
func (me *Validation) Rangef(field, input string, min, max float64) *Error
Rangef returns error if the provided input is between {min} and {max}, nil otherwise.
func (*Validation) Rangelen ¶
func (me *Validation) Rangelen(field, input string, min, max int) *Error
Rangelen returns error if the provided input is between {min} and {max} characters long, nil otherwise.
func (*Validation) Required ¶
func (me *Validation) Required(field, input string) *Error
Required returns error if the provided input is empty, nil otherwise.
func (*Validation) Tel ¶
func (me *Validation) Tel(field, input string) *Error
Tel returns error if the provided input is not an tel, nil otherwise.
func (*Validation) URL ¶
func (me *Validation) URL(field, input string) *Error
URL returns error if the provided input is not an URL, nil otherwise.
func (*Validation) Zipcode ¶
func (me *Validation) Zipcode(field, input string) *Error
Zipcode returns error if the provided input is not an zipcode, nil otherwise.