Documentation
¶
Overview ¶
Package validator provides input validation utilities with error collection
Index ¶
- Variables
- func Matches(value string, rx *regexp.Regexp) bool
- func MaxChars(value string, n int) bool
- func MinChars(value string, n int) bool
- func NotBlank(value string) bool
- func PermittedValue[T comparable](value T, permittedValues ...T) bool
- func Unique[T comparable](values []T) bool
- type Validator
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])?)+\\.[a-zA-Z]{2,}$")
)
Functions ¶
func Matches ¶
Matches returns true if value matches the regex pattern Commonly used with EmailRX for email validation
func PermittedValue ¶
func PermittedValue[T comparable](value T, permittedValues ...T) bool
PermittedValue returns true if value is in the permitted list Works with any comparable type (strings, ints, etc.)
func Unique ¶
func Unique[T comparable](values []T) bool
Unique returns true if all slice values are distinct Works with any comparable type
Types ¶
type Validator ¶
Validator collects validation errors by field name
func New ¶
func New() *Validator
New creates a Validator instance ready to collect validation errors
func (*Validator) AddError ¶
AddError records a validation error for a field Existing errors for the same field are preserved (no overwrite)
Click to show internal directories.
Click to hide internal directories.