Help us shape the future of Go! Take the 2026 Go Developer Survey

validator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package validator collects per-field form validation errors.

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])?)*$")

IsEmail returns true if the value is a valid email address this is the recommended Regular Expression for valid emails

Functions

func IsValidEmail

func IsValidEmail(email string) bool

func MaxLength

func MaxLength(value string, n int) bool

MaxLength returns true if the value contains no more than n characters

func MinLength

func MinLength(value string, n int) bool

MinLength returns true if the value contains at least n characters

func NotBlank

func NotBlank(value string) bool

returns true if data is present in the input box

Types

type Validator

type Validator struct {
	Errors map[string]string
}

Validator type is just a map

func NewValidator

func NewValidator() *Validator

We create a new Validator using a factory function We have used factory functions before

func (*Validator) AddError

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

Add an error entry to the error map. the field and the failed validation message to be sent to the client

func (*Validator) Check

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

CheckField adds an error if the validation check fails

func (*Validator) ValidData

func (v *Validator) ValidData() bool

Is the data good?

Jump to

Keyboard shortcuts

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