valid

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	PatternEmail        = `^(?i)([A-Za-z0-9!#$%&'*+\/=?^_{|.}~-]+@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)$`
	PatternURL          = `` /* 178-byte string literal not displayed */
	PatternAlpha string = `^[a-zA-Z]+$`
)
View Source
const (
	LeftOpen    = '('
	LeftSquare  = '['
	RightOpen   = ')'
	RightSquare = ']'
)

Variables

View Source
var (
	// Tag is the default tag key for validation.
	Tag = "valid"
)

Functions

func Prompt

func Prompt(name, msg string)

Prompt sets the default validation message for rules.

func Register

func Register(name string, rule Rule)

Register adds a rule to default validator.

func Validate

func Validate(i interface{}) error

Validate checks value of struct is available.

Types

type Argument

type Argument struct {
	Value       string
	Left, Right ArgumentFlag
}

func (*Argument) String

func (arg *Argument) String() string

type ArgumentFlag

type ArgumentFlag byte

type Context

type Context struct {
	Value reflect.Value
	Info  *reflect.StructField
	// contains filtered or unexported fields
}

type Error

type Error struct {
	Field string
	Rule  string
	// contains filtered or unexported fields
}

func (*Error) Cause

func (e *Error) Cause() error

func (*Error) Error

func (e *Error) Error() string

type Rule

type Rule func(ctx *Context, arg *Argument) error

type Validator

type Validator struct {
	Tag string
	// contains filtered or unexported fields
}

Validator is a struct data validator.

func (*Validator) Prompt

func (v *Validator) Prompt(name, msg string)

Prompt sets the validation message for rules.

func (*Validator) Register

func (v *Validator) Register(name string, rule Rule)

Register adds a rule to validator.

func (*Validator) Validate

func (v *Validator) Validate(i interface{}) error

Validate checks value of struct is available.

Jump to

Keyboard shortcuts

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