Documentation
¶
Overview ¶
Package validator provides comprehensive, reusable input validators for Go applications.
The package offers both simple validation functions and advanced generic validators for type-safe validation of numbers, strings, and parsed values. Validators are designed to be composable and reusable across different parts of an application.
Basic Usage ¶
Simple validation functions for common checks:
import "github.com/julianstephens/go-utils/validator"
if err := validator.ValidateNonEmpty("input"); err != nil {
// handle empty input
}
Advanced Generic Validators ¶
For comprehensive validation, use the generic validator factories:
// Number validation
numValidator := validator.Numbers[int]()
if err := numValidator.ValidateRange(42, 1, 100); err != nil {
// handle invalid number
}
// String validation
strValidator := validator.Strings[string]()
if err := strValidator.ValidateMinLength("hello", 3); err != nil {
// handle string too short
}
// Parsing validation (accessed through string validator)
strValidator := validator.Strings[string]()
if err := strValidator.Parse.ValidateEmail("[email protected]"); err != nil {
// handle invalid email
}
Type Constraints ¶
The package uses Go generics with type constraints:
- Number: ~int, ~uint, ~float32, ~float64 variants
- StringLike: ~string, ~[]byte, ~[]rune
- Emptyable: types that can be checked for emptiness
Error Handling ¶
All validators return detailed ValidationError instances with context about what was expected vs. what was received, making debugging easier.
Index ¶
- Variables
- func All(validators ...func() error) error
- func Any(validators ...func() error) error
- func OneOf[T comparable](input T, allowed ...T) error
- func ValidateMapHasKey[K comparable, V any](input map[K]V, key K) error
- func ValidateMapMaxLength[K comparable, V any](input map[K]V, max int) error
- func ValidateMapMinLength[K comparable, V any](input map[K]V, min int) error
- func ValidateMapNotHasKey[K comparable, V any](input map[K]V, key K) error
- func ValidateMatchesField[T comparable](value1 T, value2 T, fieldName string) error
- func ValidateNonEmpty[T Emptyable](input T) error
- func ValidateSliceContains[T comparable](input []T, element T) error
- func ValidateSliceLength[T any](input []T, length int) error
- func ValidateSliceLengthRange[T any](input []T, min, max int) error
- func ValidateSliceMaxLength[T any](input []T, max int) error
- func ValidateSliceMinLength[T any](input []T, min int) error
- func ValidateSliceNotContains[T comparable](input []T, element T) error
- func ValidateSliceUnique[T comparable](input []T) error
- type CustomValidator
- type Emptyable
- type Integer
- type Number
- type NumberValidator
- func (nv *NumberValidator[T]) Errorf(cause string, want, have any, err error) *ValidationError
- func (nv *NumberValidator[T]) ValidateBetween(input T, lower T, upper T) error
- func (nv *NumberValidator[T]) ValidateConsecutive(input1, input2 T) error
- func (nv *NumberValidator[T]) ValidateDivisibleBy(input T, divisor T) error
- func (nv *NumberValidator[T]) ValidateEqual(input T, expected T) error
- func (nv *NumberValidator[T]) ValidateEven(input T) error
- func (nv *NumberValidator[T]) ValidateFibonacci(input T) error
- func (nv *NumberValidator[T]) ValidateGreaterThan(input T, threshold T) error
- func (nv *NumberValidator[T]) ValidateGreaterThanOrEqual(input T, threshold T) error
- func (nv *NumberValidator[T]) ValidateLessThan(input T, threshold T) error
- func (nv *NumberValidator[T]) ValidateLessThanOrEqual(input T, threshold T) error
- func (nv *NumberValidator[T]) ValidateMax(input T, max T) error
- func (nv *NumberValidator[T]) ValidateMin(input T, min T) error
- func (nv *NumberValidator[T]) ValidateNegative(input T) error
- func (nv *NumberValidator[T]) ValidateNonNegative(input T) error
- func (nv *NumberValidator[T]) ValidateNonPositive(input T) error
- func (nv *NumberValidator[T]) ValidateNonZero(input T) error
- func (nv *NumberValidator[T]) ValidateNotEqual(input T, notExpected T) error
- func (nv *NumberValidator[T]) ValidateOdd(input T) error
- func (nv *NumberValidator[T]) ValidatePositive(input T) error
- func (nv *NumberValidator[T]) ValidatePowerOf(input T, base T) error
- func (nv *NumberValidator[T]) ValidateRange(input T, min, max T) error
- func (nv *NumberValidator[T]) ValidateZero(input T) error
- type ParseValidator
- func (pv *ParseValidator) Errorf(cause string, want, have any, err error) error
- func (pv *ParseValidator) ValidateBool(input string) error
- func (pv *ParseValidator) ValidateDate(input string, format string) error
- func (pv *ParseValidator) ValidateDuration(input string) error
- func (pv *ParseValidator) ValidateEmail(input string) error
- func (pv *ParseValidator) ValidateFloat(input string) error
- func (pv *ParseValidator) ValidateIPAddress(input string) error
- func (pv *ParseValidator) ValidateIPv4(input string) error
- func (pv *ParseValidator) ValidateIPv6(input string) error
- func (pv *ParseValidator) ValidateInt(input string) error
- func (pv *ParseValidator) ValidateNonNegativeInt(input string) error
- func (pv *ParseValidator) ValidatePassword(input string) error
- func (pv *ParseValidator) ValidatePhoneNumber(input string) error
- func (pv *ParseValidator) ValidatePositiveFloat(input string) error
- func (pv *ParseValidator) ValidatePositiveInt(input string) error
- func (pv *ParseValidator) ValidateURL(input string) error
- func (pv *ParseValidator) ValidateUUID(input string) error
- func (pv *ParseValidator) ValidateUint(input string) error
- type StringLike
- type StringValidator
- func (sv *StringValidator[T]) Errorf(cause string, want, have any, err error) *ValidationError
- func (sv *StringValidator[T]) ValidateAlpha(input T) error
- func (sv *StringValidator[T]) ValidateAlphanumeric(input T) error
- func (sv *StringValidator[T]) ValidateContains(input T, substring string) error
- func (sv *StringValidator[T]) ValidateLengthRange(input T, min, max int) error
- func (sv *StringValidator[T]) ValidateLowercase(input T) error
- func (sv *StringValidator[T]) ValidateMaxLength(input T, max int) error
- func (sv *StringValidator[T]) ValidateMinLength(input T, min int) error
- func (sv *StringValidator[T]) ValidateNotContains(input T, substring string) error
- func (sv *StringValidator[T]) ValidateNumeric(input T) error
- func (sv *StringValidator[T]) ValidatePattern(input T, pattern string) error
- func (sv *StringValidator[T]) ValidatePrefix(input T, prefix string) error
- func (sv *StringValidator[T]) ValidateSlug(input T) error
- func (sv *StringValidator[T]) ValidateSuffix(input T, suffix string) error
- func (sv *StringValidator[T]) ValidateUppercase(input T) error
- type ValidationError
- type ValidationModule
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyInput = fmt.Errorf("input cannot be empty") ErrInvalidInput = fmt.Errorf("invalid input") ErrInvalidFormat = fmt.Errorf("invalid format") ErrTooShort = fmt.Errorf("input is too short") ErrTooLong = fmt.Errorf("input is too long") ErrMissingUppercase = fmt.Errorf("missing uppercase letter") ErrMissingLowercase = fmt.Errorf("missing lowercase letter") ErrMissingDigit = fmt.Errorf("missing digit") ErrMissingSpecialChar = fmt.Errorf("missing special character") ErrStringTooShort = fmt.Errorf("string is too short") ErrStringTooLong = fmt.Errorf("string is too long") ErrStringLengthOutOfRange = fmt.Errorf("string length out of range") ErrInvalidPattern = fmt.Errorf("string does not match pattern") ErrNotAlphanumeric = fmt.Errorf("string contains non-alphanumeric characters") ErrNotAlpha = fmt.Errorf("string contains non-alphabetic characters") ErrNotNumeric = fmt.Errorf("string contains non-numeric characters") ErrInvalidSlug = fmt.Errorf("string is not a valid slug") ErrNotLowercase = fmt.Errorf("string contains uppercase characters") ErrNotUppercase = fmt.Errorf("string contains lowercase characters") ErrNotContains = fmt.Errorf("string does not contain substring") ErrContains = fmt.Errorf("string contains substring") ErrInvalidPrefix = fmt.Errorf("string does not have expected prefix") ErrInvalidSuffix = fmt.Errorf("string does not have expected suffix") ErrInvalidInteger = fmt.Errorf("invalid integer") ErrInvalidFloat = fmt.Errorf("invalid float") ErrInvalidBoolean = fmt.Errorf("invalid boolean") ErrInvalidUUID = fmt.Errorf("invalid UUID") ErrInvalidEmail = fmt.Errorf("invalid email") ErrInvalidURL = fmt.Errorf("invalid URL") ErrInvalidIPAddress = fmt.Errorf("invalid IP address") ErrInvalidIPv4 = fmt.Errorf("invalid IPv4 address") ErrInvalidIPv6 = fmt.Errorf("invalid IPv6 address") ErrInvalidDate = fmt.Errorf("invalid date") ErrInvalidDuration = fmt.Errorf("invalid duration") ErrInvalidPhone = fmt.Errorf("invalid phone number") ErrNotInSet = fmt.Errorf("value not in allowed set") ErrSliceTooShort = fmt.Errorf("slice is too short") ErrSliceTooLong = fmt.Errorf("slice is too long") ErrFieldMismatch = fmt.Errorf("field values do not match") ErrNumberTooSmall = fmt.Errorf("number is too small") ErrNumberTooLarge = fmt.Errorf("number is too large") ErrNotPositive = fmt.Errorf("number is not positive") ErrNotNegative = fmt.Errorf("number is not negative") ErrNotZero = fmt.Errorf("number is not zero") ErrNumberOutOfRange = fmt.Errorf("number out of range") ErrNotEqual = fmt.Errorf("number not equal") ErrNumberZero = fmt.Errorf("number is zero") ErrNumberPositive = fmt.Errorf("number is positive") ErrNumberNegative = fmt.Errorf("number is negative") ErrNotGreaterThan = fmt.Errorf("number not greater than threshold") ErrNotLessThan = fmt.Errorf("number not less than threshold") ErrUnsupportedType = fmt.Errorf("unsupported type") )
Functions ¶
func OneOf ¶ added in v0.3.1
func OneOf[T comparable](input T, allowed ...T) error
OneOf validates that a value is one of the allowed values
func ValidateMapHasKey ¶ added in v0.3.1
func ValidateMapHasKey[K comparable, V any](input map[K]V, key K) error
ValidateMapHasKey validates that a map contains the specified key
func ValidateMapMaxLength ¶ added in v0.3.1
func ValidateMapMaxLength[K comparable, V any](input map[K]V, max int) error
ValidateMapMaxLength validates that a map has at most the maximum number of entries
func ValidateMapMinLength ¶ added in v0.3.1
func ValidateMapMinLength[K comparable, V any](input map[K]V, min int) error
ValidateMapMinLength validates that a map has at least the minimum number of entries
func ValidateMapNotHasKey ¶ added in v0.3.1
func ValidateMapNotHasKey[K comparable, V any](input map[K]V, key K) error
ValidateMapNotHasKey validates that a map does not contain the specified key
func ValidateMatchesField ¶ added in v0.3.1
func ValidateMatchesField[T comparable](value1 T, value2 T, fieldName string) error
ValidateMatchesField validates that two comparable values are equal (useful for password confirmation)
func ValidateNonEmpty ¶
ValidateNonEmpty validates that input is not empty
func ValidateSliceContains ¶ added in v0.3.1
func ValidateSliceContains[T comparable](input []T, element T) error
ValidateSliceContains validates that a slice contains the specified element
func ValidateSliceLength ¶ added in v0.3.1
ValidateSliceLength validates that a slice has the specified length
func ValidateSliceLengthRange ¶ added in v0.3.1
ValidateSliceLengthRange validates that a slice length is within the specified range (inclusive)
func ValidateSliceMaxLength ¶ added in v0.3.1
ValidateSliceMaxLength validates that a slice has at most the maximum length
func ValidateSliceMinLength ¶ added in v0.3.1
ValidateSliceMinLength validates that a slice has at least the minimum length
func ValidateSliceNotContains ¶ added in v0.3.1
func ValidateSliceNotContains[T comparable](input []T, element T) error
ValidateSliceNotContains validates that a slice does not contain the specified element
func ValidateSliceUnique ¶ added in v0.3.1
func ValidateSliceUnique[T comparable](input []T) error
ValidateSliceUnique validates that all elements in a slice are unique
Types ¶
type CustomValidator ¶ added in v0.3.1
type CustomValidator struct {
// contains filtered or unexported fields
}
CustomValidator provides a builder pattern for composing multiple validators
func NewCustomValidator ¶ added in v0.3.1
func NewCustomValidator() *CustomValidator
NewCustomValidator creates a new CustomValidator instance
func (*CustomValidator) Add ¶ added in v0.3.1
func (cv *CustomValidator) Add(validator func() error) *CustomValidator
Add appends a validator function to the custom validator
func (*CustomValidator) SafeValidate ¶ added in v0.4.2
func (cv *CustomValidator) SafeValidate() (returnErr error)
SafeValidate runs all accumulated validators in sequence with panic recovery. If any validator panics, the panic is recovered and logged to stderr. This prevents validation errors from crashing the application. Use in critical paths where you want validation to fail gracefully.
func (*CustomValidator) Validate ¶ added in v0.3.1
func (cv *CustomValidator) Validate() error
Validate runs all accumulated validators in sequence (AND logic)
type Integer ¶ added in v0.3.1
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
Type constraints
type NumberValidator ¶ added in v0.3.0
type NumberValidator[T Number] struct{}
func Numbers ¶ added in v0.3.0
func Numbers[T Number]() *NumberValidator[T]
Numbers returns a NumberValidator for the specified numeric type.
func (*NumberValidator[T]) Errorf ¶ added in v0.3.0
func (nv *NumberValidator[T]) Errorf(cause string, want, have any, err error) *ValidationError
func (*NumberValidator[T]) ValidateBetween ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateBetween(input T, lower T, upper T) error
ValidateBetween validates that a number is within the specified bounds (inclusive)
func (*NumberValidator[T]) ValidateConsecutive ¶ added in v0.3.1
func (nv *NumberValidator[T]) ValidateConsecutive(input1, input2 T) error
ValidateConsecutive validates that the second number is exactly one greater than the first
func (*NumberValidator[T]) ValidateDivisibleBy ¶ added in v0.3.1
func (nv *NumberValidator[T]) ValidateDivisibleBy(input T, divisor T) error
ValidateDivisibleBy validates that a number is evenly divisible by the divisor (integer types only)
func (*NumberValidator[T]) ValidateEqual ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateEqual(input T, expected T) error
ValidateEqual validates that a number equals the expected value
func (*NumberValidator[T]) ValidateEven ¶ added in v0.3.1
func (nv *NumberValidator[T]) ValidateEven(input T) error
ValidateEven validates that a number is even (integer types only)
func (*NumberValidator[T]) ValidateFibonacci ¶ added in v0.3.1
func (nv *NumberValidator[T]) ValidateFibonacci(input T) error
ValidateFibonacci validates that a number is a Fibonacci number (integer types only)
func (*NumberValidator[T]) ValidateGreaterThan ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateGreaterThan(input T, threshold T) error
ValidateGreaterThan validates that a number is strictly greater than the threshold
func (*NumberValidator[T]) ValidateGreaterThanOrEqual ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateGreaterThanOrEqual(input T, threshold T) error
ValidateGreaterThanOrEqual validates that a number is greater than or equal to the threshold
func (*NumberValidator[T]) ValidateLessThan ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateLessThan(input T, threshold T) error
ValidateLessThan validates that a number is strictly less than the threshold
func (*NumberValidator[T]) ValidateLessThanOrEqual ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateLessThanOrEqual(input T, threshold T) error
ValidateLessThanOrEqual validates that a number is less than or equal to the threshold
func (*NumberValidator[T]) ValidateMax ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateMax(input T, max T) error
ValidateMax validates that a number is less than or equal to the maximum value
func (*NumberValidator[T]) ValidateMin ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateMin(input T, min T) error
ValidateMin validates that a number is greater than or equal to the minimum value
func (*NumberValidator[T]) ValidateNegative ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateNegative(input T) error
ValidateNegative validates that a number is less than zero
func (*NumberValidator[T]) ValidateNonNegative ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateNonNegative(input T) error
ValidateNonNegative validates that a number is greater than or equal to zero
func (*NumberValidator[T]) ValidateNonPositive ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateNonPositive(input T) error
ValidateNonPositive validates that a number is less than or equal to zero
func (*NumberValidator[T]) ValidateNonZero ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateNonZero(input T) error
ValidateNonZero validates that a number is not equal to zero
func (*NumberValidator[T]) ValidateNotEqual ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateNotEqual(input T, notExpected T) error
ValidateNotEqual validates that a number is not equal to the specified value
func (*NumberValidator[T]) ValidateOdd ¶ added in v0.3.1
func (nv *NumberValidator[T]) ValidateOdd(input T) error
ValidateOdd validates that a number is odd (integer types only)
func (*NumberValidator[T]) ValidatePositive ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidatePositive(input T) error
ValidatePositive validates that a number is greater than zero
func (*NumberValidator[T]) ValidatePowerOf ¶ added in v0.3.1
func (nv *NumberValidator[T]) ValidatePowerOf(input T, base T) error
ValidatePowerOf validates that a number is a power of the specified base (integer types only)
func (*NumberValidator[T]) ValidateRange ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateRange(input T, min, max T) error
ValidateRange validates that a number is within the specified range (inclusive)
func (*NumberValidator[T]) ValidateZero ¶ added in v0.3.0
func (nv *NumberValidator[T]) ValidateZero(input T) error
ValidateZero validates that a number equals zero
type ParseValidator ¶ added in v0.3.0
type ParseValidator struct{}
func Parse ¶ added in v0.3.0
func Parse() *ParseValidator
Parse returns a ParseValidator for parsing string inputs.
func (*ParseValidator) Errorf ¶ added in v0.3.0
func (pv *ParseValidator) Errorf(cause string, want, have any, err error) error
func (*ParseValidator) ValidateBool ¶ added in v0.3.0
func (pv *ParseValidator) ValidateBool(input string) error
ValidateBool validates that input can be parsed as a boolean
func (*ParseValidator) ValidateDate ¶ added in v0.3.1
func (pv *ParseValidator) ValidateDate(input string, format string) error
ValidateDate validates that input can be parsed as a date in the specified format
func (*ParseValidator) ValidateDuration ¶ added in v0.3.1
func (pv *ParseValidator) ValidateDuration(input string) error
ValidateDuration validates that input can be parsed as a duration (e.g., "5m", "2h", "1s")
func (*ParseValidator) ValidateEmail ¶ added in v0.3.0
func (pv *ParseValidator) ValidateEmail(input string) error
func (*ParseValidator) ValidateFloat ¶ added in v0.3.0
func (pv *ParseValidator) ValidateFloat(input string) error
ValidateFloat validates that input can be parsed as a float
func (*ParseValidator) ValidateIPAddress ¶ added in v0.3.0
func (pv *ParseValidator) ValidateIPAddress(input string) error
ValidateIPAddress validates that input is a valid IP address (IPv4 or IPv6)
func (*ParseValidator) ValidateIPv4 ¶ added in v0.3.0
func (pv *ParseValidator) ValidateIPv4(input string) error
ValidateIPv4 validates that input is a valid IPv4 address
func (*ParseValidator) ValidateIPv6 ¶ added in v0.3.0
func (pv *ParseValidator) ValidateIPv6(input string) error
ValidateIPv6 validates that input is a valid IPv6 address
func (*ParseValidator) ValidateInt ¶ added in v0.3.0
func (pv *ParseValidator) ValidateInt(input string) error
ValidateInt validates that input can be parsed as an integer
func (*ParseValidator) ValidateNonNegativeInt ¶ added in v0.3.0
func (pv *ParseValidator) ValidateNonNegativeInt(input string) error
ValidateNonNegativeInt validates that input is a non-negative integer
func (*ParseValidator) ValidatePassword ¶ added in v0.3.0
func (pv *ParseValidator) ValidatePassword(input string) error
func (*ParseValidator) ValidatePhoneNumber ¶ added in v0.3.1
func (pv *ParseValidator) ValidatePhoneNumber(input string) error
ValidatePhoneNumber validates that input is a valid phone number (basic format: digits, spaces, hyphens, +)
func (*ParseValidator) ValidatePositiveFloat ¶ added in v0.3.0
func (pv *ParseValidator) ValidatePositiveFloat(input string) error
ValidatePositiveFloat validates that input is a positive float
func (*ParseValidator) ValidatePositiveInt ¶ added in v0.3.0
func (pv *ParseValidator) ValidatePositiveInt(input string) error
ValidatePositiveInt validates that input is a positive integer
func (*ParseValidator) ValidateURL ¶ added in v0.3.0
func (pv *ParseValidator) ValidateURL(input string) error
ValidateURL validates that input is a valid URL
func (*ParseValidator) ValidateUUID ¶ added in v0.3.0
func (pv *ParseValidator) ValidateUUID(input string) error
func (*ParseValidator) ValidateUint ¶ added in v0.3.0
func (pv *ParseValidator) ValidateUint(input string) error
ValidateUint validates that input can be parsed as an unsigned integer
type StringLike ¶ added in v0.3.0
type StringValidator ¶ added in v0.3.0
type StringValidator[T StringLike] struct { Parse *ParseValidator }
func Strings ¶ added in v0.3.0
func Strings[T StringLike]() *StringValidator[T]
Strings returns a StringValidator for the specified string-like type.
func (*StringValidator[T]) Errorf ¶ added in v0.3.0
func (sv *StringValidator[T]) Errorf(cause string, want, have any, err error) *ValidationError
func (*StringValidator[T]) ValidateAlpha ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateAlpha(input T) error
ValidateAlpha validates that a string contains only alphabetic characters
func (*StringValidator[T]) ValidateAlphanumeric ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateAlphanumeric(input T) error
ValidateAlphanumeric validates that a string contains only alphanumeric characters
func (*StringValidator[T]) ValidateContains ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateContains(input T, substring string) error
ValidateContains validates that a string contains the specified substring
func (*StringValidator[T]) ValidateLengthRange ¶ added in v0.3.0
func (sv *StringValidator[T]) ValidateLengthRange(input T, min, max int) error
ValidateLengthRange validates that a string length is within the specified range (inclusive)
func (*StringValidator[T]) ValidateLowercase ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateLowercase(input T) error
ValidateLowercase validates that a string contains only lowercase characters (letters only)
func (*StringValidator[T]) ValidateMaxLength ¶ added in v0.3.0
func (sv *StringValidator[T]) ValidateMaxLength(input T, max int) error
ValidateMaxLength validates that a string is at most the maximum length
func (*StringValidator[T]) ValidateMinLength ¶ added in v0.3.0
func (sv *StringValidator[T]) ValidateMinLength(input T, min int) error
ValidateMinLength validates that a string is at least the minimum length
func (*StringValidator[T]) ValidateNotContains ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateNotContains(input T, substring string) error
ValidateNotContains validates that a string does not contain the specified substring
func (*StringValidator[T]) ValidateNumeric ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateNumeric(input T) error
ValidateNumeric validates that a string contains only numeric characters
func (*StringValidator[T]) ValidatePattern ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidatePattern(input T, pattern string) error
ValidatePattern validates that a string matches the specified regex pattern
func (*StringValidator[T]) ValidatePrefix ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidatePrefix(input T, prefix string) error
ValidatePrefix validates that a string starts with the specified prefix
func (*StringValidator[T]) ValidateSlug ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateSlug(input T) error
ValidateSlug validates that a string is a valid URL slug (lowercase alphanumeric with hyphens and underscores)
func (*StringValidator[T]) ValidateSuffix ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateSuffix(input T, suffix string) error
ValidateSuffix validates that a string ends with the specified suffix
func (*StringValidator[T]) ValidateUppercase ¶ added in v0.3.1
func (sv *StringValidator[T]) ValidateUppercase(input T) error
ValidateUppercase validates that a string contains only uppercase characters (letters only)
type ValidationError ¶ added in v0.3.0
type ValidationError struct {
Module ValidationModule
Cause string
Want any
Have any
Err error
}
func NewValidationError ¶ added in v0.3.0
func NewValidationError(module ValidationModule, cause string, want, have any, err error) *ValidationError
func (*ValidationError) Error ¶ added in v0.3.0
func (ve *ValidationError) Error() string
type ValidationModule ¶ added in v0.3.0
type ValidationModule int
const ( ModuleUnknown ValidationModule = iota ModuleParse ModuleString ModuleNumber )