Documentation ¶
Index ¶
- func Accepted() func(value string) error
- func CountryCodeISO3166Alpha2() func(value string) error
- func CountryCodeISO3166Alpha3() func(value string) error
- func Max[T constraints.Ordered](max T) func(value T) error
- func Min[T constraints.Ordered](min T) func(value T) error
- func PrintableASCII() func(value string) error
- func PrintableUTF8() func(value string) error
- func Regex(pattern string) func(value string) error
- func Size[T ~string | ~[]S, S any](min uint, max uint) func(value T) error
- type ErrASCII
- type ErrAccepted
- type ErrCountryCode
- type ErrMax
- type ErrMin
- type ErrRegex
- type ErrSize
- type ErrUTF8
- type RuleSet
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accepted ¶
The value under validation must be "yes" or "on". This is useful for validating checkbox/boolean html form fields such as "Terms of Service" acceptance.
func Max ¶
func Max[T constraints.Ordered](max T) func(value T) error
The field under validation must be less than or equal to the maximum value.
func Min ¶
func Min[T constraints.Ordered](min T) func(value T) error
The field under validation must be more than or equal to the minimum value.
func PrintableASCII ¶ added in v0.2.0
func PrintableUTF8 ¶ added in v0.4.0
Types ¶
type ErrASCII ¶ added in v0.2.0
type ErrASCII struct {
// contains filtered or unexported fields
}
func NewErrASCII ¶ added in v0.5.0
type ErrAccepted ¶
type ErrAccepted struct {
// contains filtered or unexported fields
}
func NewErrAccepted ¶ added in v0.5.0
func NewErrAccepted(value string) ErrAccepted
func (ErrAccepted) Error ¶
func (err ErrAccepted) Error() string
type ErrCountryCode ¶
type ErrCountryCode struct {
// contains filtered or unexported fields
}
func NewErrCountryCode ¶ added in v0.5.0
func NewErrCountryCode(value string, format string) ErrCountryCode
func (ErrCountryCode) Error ¶
func (err ErrCountryCode) Error() string
type ErrMax ¶
type ErrMax[T constraints.Ordered] struct { // contains filtered or unexported fields }
func NewErrMax ¶ added in v0.5.0
func NewErrMax[T constraints.Ordered](value T, max T) ErrMax[T]
type ErrMin ¶
type ErrMin[T constraints.Ordered] struct { // contains filtered or unexported fields }
func NewErrMin ¶ added in v0.5.0
func NewErrMin[T constraints.Ordered](value T, min T) ErrMin[T]
type ErrRegex ¶
type ErrRegex struct {
// contains filtered or unexported fields
}
func NewErrRegex ¶ added in v0.5.0
type ErrSize ¶ added in v0.3.0
func NewErrSize ¶ added in v0.5.0
type ErrUTF8 ¶ added in v0.4.0
type ErrUTF8 struct {
// contains filtered or unexported fields
}
func NewErrUTF8 ¶ added in v0.5.0
type RuleSet ¶
func Rule ¶
Example ¶
package main import ( "fmt" "gitlab.com/JankTech/hail" ) func main() { v := 123 r, err := hail.Rule(hail.Min(130), hail.Max(110)) if err != nil { panic(err) } ok, errs := r.Validate(v) if !ok { for _, err = range errs { fmt.Println(err.Error()) } } }
Output: value 123 is less than min 130 value 123 is more than max 110
Click to show internal directories.
Click to hide internal directories.