validator

package
v0.0.0-...-33f6d27 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 3 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 expression to validate the format of an email string.

Functions

func Matches

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

Validates a string against a regex expression.

func MaxChars

func MaxChars(value string, n int) bool

MaxChars() returns true if the length of the input string is not greater than the limit n.

func MinChars

func MinChars(value string, n int) bool

MinChars() returns true if the length of the input string is at least n.

func NotBlank

func NotBlank(value string) bool

NotBlank() returns true if a value is a non-empty string.

func PermittedValue

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

PermittedInt() returns true if a value is in a list of permitted integers.

Types

type Validator

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

Define a new Validator type which contains a map of validation errors for form data.

func (*Validator) AddFieldError

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

AddFieldError() adds a [form field name : error message] mapping to the FieldErrors map, so long as an entry does not already exist.

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

AddNonFieldError adds an error message to the NonFieldErrors string array, which stores error messages for validation errors not related to the form field data.

func (*Validator) CheckField

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

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

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid() returns true if the FieldErrors map contains no entries.

Jump to

Keyboard shortcuts

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