Documentation ¶
Index ¶
- Variables
- func Matches(value string, rx *regexp.Regexp) bool
- func PermittedValue[T comparable](value T, permittedValues ...T) bool
- func Unique[T comparable](values []T) bool
- func ValidateEmail(v *Validator, email string)
- func ValidateStrLenByte(v *Validator, value, key string, min, max int)
- func ValidateStrLenRune(v *Validator, value, key string, min, max int)
- func ValidateURL(v *Validator, value, key string)
- func ValidateURLHTTP(v *Validator, value, key string)
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( BetterGUIDRX = regexp.MustCompile("^[a-zA-Z0-9_-]{20}$") 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])?)*$") UsernameRX = regexp.MustCompile("^[A-Za-z0-9][A-Za-z0-9_-]{3,30}[A-Za-z0-9]") )
Functions ¶
func PermittedValue ¶
func PermittedValue[T comparable](value T, permittedValues ...T) bool
PermittedValue checks that the comparable value of type T is one of the provided permittedValues.
func Unique ¶
func Unique[T comparable](values []T) bool
Unique checks that the given slice of comparable values of type T contains only unique values.
func ValidateEmail ¶
ValidateEmail performs standard validation checks against the provided email address and populates any errors into v.
func ValidateStrLenByte ¶
ValidateStrLenByte validates that the given string is between min and max bytes long. Any errors are saved into the given key in the given Validator's Error map.
func ValidateStrLenRune ¶
ValidateStrLenRune validates that the given string is between min and max runes (characters) long. Any errors are saved into the given key in the given Validator's Error map.
func ValidateURL ¶
ValidateURL validates that the given string can be parsed as a URL.
func ValidateURLHTTP ¶
ValidateURLHTTP validates that the given string can be parsed as a URL and that the scheme is an HTTP one.
Types ¶
type Validator ¶
A Validator is simply a map from field names to error messages.
func (*Validator) AddError ¶
AddError adds a single, new validation error to the Errors map. If an error with the same key already exists, then this is a no-op.