Documentation
¶
Overview ¶
Package validator implements utility for input validation
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 Matches ¶
Matches checks if a string value matches the provided regular expression Returns true if the string matches the pattern, false otherwise Commonly used with the EmailRX variable for email validation
func PermittedValue ¶
func PermittedValue[T comparable](value T, permittedValues ...T) bool
PermittedValue checks if a value exists within a list of permitted values Uses Go generics to work with any comparable type (strings, ints, etc.) Returns true if the value is found in the permitted values slice
func Unique ¶
func Unique[T comparable](values []T) bool
Unique checks if all values in a slice are unique (no duplicates) Uses Go generics to work with slices of any comparable type Returns true if all values are unique, false if duplicates are found
Types ¶
type Validator ¶
Validator holds a map of validation errors keyed by field name This allows accumulating multiple validation errors before returning them
func New ¶
func New() *Validator
New creates and returns a new Validator instance with an empty error map
func (*Validator) AddError ¶
AddError adds a validation error message for the given field key If an error already exists for this key, it will not be overwritten This prevents duplicate error messages for the same field