validation

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Errors

type Errors map[string][]string

Errors holds validation error messages keyed by field name.

func (Errors) Add

func (e Errors) Add(field, message string)

Add appends an error message for a field.

func (Errors) First

func (e Errors) First(field string) string

First returns the first error message for a field, or empty string.

func (Errors) HasErrors

func (e Errors) HasErrors() bool

HasErrors returns true if any validation errors exist.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator performs fluent, chainable input validation.

func New

func New() *Validator

New creates a new Validator instance.

func (*Validator) Confirmed

func (v *Validator) Confirmed(field, value, confirmation string) *Validator

Confirmed checks two values match (e.g. password confirmation).

func (*Validator) Email

func (v *Validator) Email(field, value string) *Validator

Email validates email format using net/mail.

func (*Validator) Errors

func (v *Validator) Errors() Errors

Errors returns the collected validation errors.

func (*Validator) IP

func (v *Validator) IP(field, value string) *Validator

IP validates an IP address.

func (*Validator) In

func (v *Validator) In(field, value string, allowed []string) *Validator

In checks value is one of the allowed options.

func (*Validator) Matches

func (v *Validator) Matches(field, value, pattern string) *Validator

Matches checks value against a regex pattern.

func (*Validator) MaxLength

func (v *Validator) MaxLength(field, value string, max int) *Validator

MaxLength checks maximum string length (rune count).

func (*Validator) MinLength

func (v *Validator) MinLength(field, value string, min int) *Validator

MinLength checks minimum string length (rune count).

func (*Validator) Required

func (v *Validator) Required(field, value string) *Validator

Required checks that the value is not empty after trimming whitespace.

func (*Validator) URL

func (v *Validator) URL(field, value string) *Validator

URL validates that value starts with http:// or https://.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid returns true if no validation errors exist.

Jump to

Keyboard shortcuts

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