validator

package
v0.0.0-...-80a305e Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 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])?)*$")

Functions

func Matches

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

Matches() returns ture if a value mathces a provided comiled regular expression pattern.

func MaxChars

func MaxChars(value string, n int) bool

MaxChars() returns true if a value is not and empty string.

func MinChars

func MinChars(value string, n int) bool

MinChars() returns 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

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
}

Validator type contains a map of validation errors

func (*Validator) AddFieldError

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

AddFieldError() adds an error message to the FieldErrors map.

func (*Validator) AddNonFieldErrors

func (v *Validator) AddNonFieldErrors(message string)

AddNonFieldErrors helper adds an error messages to the NonFieldErrors slice.

func (*Validator) ChekField

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

ChekField() adds an error message to the FieldErrors map only if a validatin ckeck is not 'ok'.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid() returns true if the FieldErrors map and NonFieldErrors doesn't contain any entries.

Jump to

Keyboard shortcuts

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