validator

package
v0.0.0-...-44a2381 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 6 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 DigitsInNumber

func DigitsInNumber(num int, n int) bool

func In

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

func IsEmail

func IsEmail(value string) bool

func IsURL

func IsURL(value string) 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

Types

type Validator

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

func New

func New() *Validator

func Validate

func Validate(fn func(v *Validator)) *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)

func (*Validator) CheckField

func (v *Validator) CheckField(ok bool, key, message 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