validation

package
v0.0.0-...-5311485 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RgxEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")

Functions

func AllIn

func AllIn[T comparable](values []T, safelist ...T) bool

func Between

func Between[T constraints.Ordered](value, min, max T) bool

func Email

func Email(value string) bool

func In

func In[T comparable](value T, safelist ...T) bool

func Length

func Length(value string, min, max int) bool

func Matches

func Matches(value string, rx *regexp.Regexp) bool

func MaxRunes

func MaxRunes(value string, n int) bool

func MinRunes

func MinRunes(value string, n int) bool

func NoDuplicates

func NoDuplicates[T comparable](values []T) bool

func NotBlank

func NotBlank(value string) bool

func NotIn

func NotIn[T comparable](value T, blocklist ...T) bool

func URL

func URL(value string) bool

func Validate

func Validate(fns ...ValidateFunc) error

Types

type ValidateFunc

type ValidateFunc func(v *Validator)

type Validator

type Validator struct {
	Errors      []string          `json:",omitempty"`
	FieldErrors map[string]string `json:",omitempty"`
}

func New

func New() *Validator

func (*Validator) AddError

func (v *Validator) AddError(message string)

func (*Validator) AddFieldError

func (v *Validator) AddFieldError(key, message string)

func (*Validator) Check

func (v *Validator) Check(ok bool, message string) bool

func (*Validator) CheckField

func (v *Validator) CheckField(ok bool, key, message string) bool

func (*Validator) Error

func (v *Validator) Error() string

func (*Validator) HasErrors

func (v *Validator) HasErrors() bool

Jump to

Keyboard shortcuts

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