validator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

package validator provides various functions to validate the user input from the forms.

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 MatchString

func MatchString(a, b string) bool

func Matches

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

func MaxChars

func MaxChars(value string, n int) bool

MaxChars checks if the characters in the field does not exceed the maximum allowed characters.

func MinChars

func MinChars(value string, n int) bool

func NotBlank

func NotBlank(value string) bool

NotBlank checks if the field is empty.

func PermittedValue

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

Types

type Validator

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

func (*Validator) AddFieldError

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

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

func (*Validator) CheckField

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

func (*Validator) Valid

func (v *Validator) Valid() bool

Jump to

Keyboard shortcuts

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