validate

package
v0.0.0-...-82e7740 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 7 Imported by: 0

README

data-validate GoDoc

validate library for Go

Installation

go get gopkg.in/goyy/goyy.v0/data/validate

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alhan

func Alhan(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 Alhanrod

func Alhanrod(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 All

func All(tests ...error) []error

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

func Alnum(input string) error

Alnum returns error if the provided input is not an alphanumeric (a-zA-Z0-9) string, nil otherwise.

func Alnumhan

func Alnumhan(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 Alnumhanrod

func Alnumhanrod(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 Alnumrod

func Alnumrod(input string) error

Alnumrod returns error if the provided input is not an alphanumeric or rod (a-zA-Z0-9\-_) string, nil otherwise.

func Alpha

func Alpha(input string) error

Alpha returns error if the provided input is not an alphabetic (a-zA-Z) string, nil otherwise.

func Alrod

func Alrod(input string) error

Alrod returns error if the provided input is not an alphabetic or rod (a-zA-Z\-_) string, nil otherwise.

func Any

func Any(tests ...error) error

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

func Chain(input string, links ...func(string) error) error

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

func Each(tests ...error) error

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 Email

func Email(input string) error

Email returns error if the provided input is not an email, nil otherwise.

func Float

func Float(input string) error

Float returns error if the provided input is not a floating point number, nil otherwise.

func Han

func Han(input string) error

Han returns error if the provided input is not an alphabetic or chinese (\p{Han}) string, nil otherwise.

func Hanrod

func Hanrod(input string) error

Hanrod returns error if the provided input is not an alphabetic or chinese or rod (\p{Han}\-_) string, nil otherwise.

func IP

func IP(input string) error

IP returns error if the provided input is not an IP, nil otherwise.

func Integer

func Integer(input string) error

Integer returns error if the provided input is not an integer value, nil otherwise.

func Match

func Match(input, regexps string) error

Match returns error if the provided input is not match {regexp} string, nil otherwise.

func Max

func Max(input string, max int) error

Max returns error if the provided input is less than or equal to {max}, nil otherwise.

func Maxf

func Maxf(input string, max float64) error

Maxf returns error if the provided input is less than or equal to {max}, nil otherwise.

func Maxlen

func Maxlen(input string, max int) error

Maxlen returns error if the provided input is more than {max} characters, nil otherwise.

func Min

func Min(input string, min int) error

Min returns error if the provided input is greater than or equal to {min}, nil otherwise.

func Minf

func Minf(input string, min float64) error

Minf returns error if the provided input is greater than or equal to {min}, nil otherwise.

func Minlen

func Minlen(input string, min int) error

Minlen returns error if the provided input is least {min} characters, nil otherwise.

func Mobile

func Mobile(input string) error

Mobile returns error if the provided input is not an mobile, nil otherwise.

func Nomatch

func Nomatch(input, regexps string) error

Nomatch returns error if the provided input is match {regexp} string, nil otherwise.

func Phone

func Phone(input string) error

Phone returns error if the provided input is not an phone, nil otherwise.

func Range

func Range(input string, min, max int) error

Range returns error if the provided input is between {min} and {max}, nil otherwise.

func Rangef

func Rangef(input string, min, max float64) error

Rangef returns error if the provided input is between {min} and {max}, nil otherwise.

func Rangelen

func Rangelen(input string, min, max int) error

Rangelen returns error if the provided input is between {min} and {max} characters long, nil otherwise.

func Required

func Required(input string) error

Required returns error if the provided input is empty, nil otherwise.

func SetLocale

func SetLocale(locale string)

SetLocale set the i18n locale.

func Tel

func Tel(input string) error

Tel returns error if the provided input is not an tel, nil otherwise.

func URL

func URL(input string) error

URL returns error if the provided input is not an URL, nil otherwise.

func Zipcode

func Zipcode(input string) error

Zipcode returns error if the provided input is not an zipcode, nil otherwise.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error validate.Error.

func (*Error) Error

func (me *Error) Error() string

func (*Error) Field

func (me *Error) Field() string

Field gets the Error.field.

func (*Error) Message

func (me *Error) Message() string

Message gets the Error.message.

func (*Error) Type

func (me *Error) Type() string

Type gets the Error.type.

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) Clear

func (me *Validation) Clear()

Clear clean all Validation Errors.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL