validator

package
v0.0.0-...-d5b6c7e Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 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])?)*$")

regex for emails recommended by W3C and Web Hypertext Application Technology Working Group

Functions

func Equal

func Equal(value1 string, value2 string) bool

checks to see if two fields are equal

func Matches

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

checks if field matches regular expression

func MaxChars

func MaxChars(value string, n int) bool

checks for max number of characters

func MinChars

func MinChars(value string, n int) bool

checks for min number of characters

func NotBlank

func NotBlank(value string) bool

checks if field is not blank

func PermittedValue

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

checks if form has a specific value

Types

type Validator

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

FielErrors are associated with a form field and NonFieldErrors are just general form errors

func (*Validator) AddFieldError

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

adds a new field error if it does not already exist

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

create a NonFieldError

func (*Validator) CheckField

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

checks for a specific field error

func (*Validator) Valid

func (v *Validator) Valid() bool

checks if form is valid

Jump to

Keyboard shortcuts

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