validator

package
v0.0.0-...-f0a4b7f Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: BSD-3-Clause 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])?)*$")

Functions

func Matches

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

Matches returns true if the value matches the regular expression.

func MaxLength

func MaxLength(value string, max int) bool

MaxLength returns true if the value is less than or equal to the max length.

func MinLength

func MinLength(value string, min int) bool

MinLength returns true if the value is greater than or equal to the min length.

func NotBlank

func NotBlank(value string) bool

NotBlank returns true if the value is not empty.

func PermittedValue

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

PermittedValue returns true if the value is in the list of permitted values.

Types

type Validator

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

Validator is a struct that contains a map of field errors.

func (*Validator) AddFieldError

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

AddFieldError adds an error message to the map of field errors.

func (*Validator) AddGeneralError

func (v *Validator) AddGeneralError(message string)

AddGeneralError adds an error message to the slice of general errors.

func (*Validator) CheckField

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

CheckField checks if a condition is met and adds an error message to the map of field errors if it is not.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid returns true if the Validator has no field errors.

Jump to

Keyboard shortcuts

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