validator

package
v0.0.0-...-2f4ffc2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxChars

func MaxChars(value string, n int) bool

MaxChars() returns true if a value contains no more than 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

PermittedValue() returns true if a value is in a list of specific permitted values.

Types

type Validator

type Validator struct {
	FieldErrors map[string]string
}

Define a new Validator struct which contains a map of validation error messages for our form fields.

func (*Validator) AddFieldError

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

AddFieldError() adds an error message to the FieldErrors map (so long as no entry already exists for the given key).

func (*Validator) CheckField

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

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

func (*Validator) Valid

func (v *Validator) Valid() bool

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

Jump to

Keyboard shortcuts

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