validator

package
v0.0.0-...-618557b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmailRegExp = 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 checks if the value matches the regular expression.

func MaxChars

func MaxChars(value string, max int) bool

MaxChars checks if the value is not longer than max characters.

func MinChars

func MinChars(value string, min int) bool

MinChars checks if the value length is greater or equal to min characters.

func NotBlank

func NotBlank(value string) bool

NotBlank checks if the value is not an empty string.

func PermittedValue

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

PermittedValue checks if the value is in the list of permitted values.

Types

type Validator

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

func (*Validator) AddFieldError

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

AddFieldError adds an error message for a specific field to the FieldErrors map.

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

func (*Validator) CheckField

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

CheckField checks a condition. If that fails, it adds an error message to the FieldErrors map.

func (*Validator) IsValid

func (v *Validator) IsValid() bool

IsValid returns true if there are no errors, otherwise false.

Jump to

Keyboard shortcuts

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