validator

package
v0.0.0-...-91a5d29 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmailRX = 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])?)*$")

precompile regexps at appilcation start up for better performance

Functions

func Matches

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

Matcher() returns true if a value matches a provided compiled regular expression.

func MaxChars

func MaxChars(value string, n int) bool

MaxChars() returns true if a value contains no more than n characters.

func MinChar

func MinChar(value string, n int) bool

MinChars() return true if a value contains at least n characters.

func NotBlank

func NotBlank(value string) bool

NotBlank() returns true if a value is not an empty string.

func PermittedValue

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

PermittedValue() returns true if a value is in a list of specific permitted values.

Types

type Validator

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

func (*Validator) AddFieldError

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

AddFieldError() adds an error message to the FieldErrors map (so long as no entry already exists for the given key).

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

AddNonFieldError() adds an error message to the NonFieldErrors slice

func (*Validator) CheckField

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

CheckField() adds an error message to the FieldErrors map only if a validation check is not 'ok'.

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