validator

package
v0.0.0-...-8c49daf Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmailRE = 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 Matches

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

Matches returns true if the given string satisfies the given regex.

func MaxChars

func MaxChars(value string, n int) bool

MaxChars returns true if the given string has at most n characters.

func MinChars

func MinChars(value string, n int) bool

MinChars returns true if the given string has at least n characters.

func NotBlank

func NotBlank(value string) bool

NotBlank returns true if the given string has at least 1 non-whitespace character.

func PermittedValue

func PermittedValue[T comparable](value T, permittedValues ...T) bool

PermittedValue returns true if the given int is present in a list of values.

Types

type Validator

type Validator struct {
	NonFieldErrors []string
	FieldErrors    map[string]string
}

func (*Validator) AddFieldError

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

AddFieldError keeps only the first message added for that particular key.

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

func (*Validator) CheckField

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

CheckField adds an error if the given condition check returns false.

func (*Validator) Valid

func (v *Validator) Valid() bool

Jump to

Keyboard shortcuts

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