Documentation
¶
Overview ¶
Package checks provides validation checks for schema validation
Package checks provides format validation checks ¶
Package checks provides length and size constraint validation ¶
Package checks provides numeric validation checks ¶
Package checks provides string validation checks
Index ¶
- func ApplyCheckParams(def *core.ZodCheckDef, params *core.CheckParams)
- func ApplySchemaParamsToCheck(def *core.ZodCheckDef, params *core.SchemaParams)
- func Base64(params ...any) core.ZodCheck
- func Base64URL(params ...any) core.ZodCheck
- func BrowserEmail(params ...any) core.ZodCheck
- func CIDRv4(params ...any) core.ZodCheck
- func CIDRv6(params ...any) core.ZodCheck
- func CUID(params ...any) core.ZodCheck
- func CUID2(params ...any) core.ZodCheck
- func E164(params ...any) core.ZodCheck
- func Email(params ...any) core.ZodCheck
- func EmailWithPattern(pattern *regexp.Regexp, params ...any) core.ZodCheck
- func Emoji(params ...any) core.ZodCheck
- func Empty(params ...any) core.ZodCheck
- func EndsWith(suffix string, params ...any) core.ZodCheck
- func FileSize(expected int64, params ...any) core.ZodCheck
- func GUID(params ...any) core.ZodCheck
- func Gt(value any, params ...any) core.ZodCheck
- func Gte(value any, params ...any) core.ZodCheck
- func Html5Email(params ...any) core.ZodCheck
- func IPv4(params ...any) core.ZodCheck
- func IPv6(params ...any) core.ZodCheck
- func ISODate(params ...any) core.ZodCheck
- func ISODateMax(maxDate string, params ...any) core.ZodCheck
- func ISODateMin(minDate string, params ...any) core.ZodCheck
- func ISODateTime(params ...any) core.ZodCheck
- func ISODateTimeWithOptions(options ISODateTimeOptions, params ...any) core.ZodCheck
- func ISODuration(params ...any) core.ZodCheck
- func ISOTime(params ...any) core.ZodCheck
- func ISOTimeWithOptions(options ISOTimeOptions, params ...any) core.ZodCheck
- func Includes(substring string, params ...any) core.ZodCheck
- func JSON(params ...any) core.ZodCheck
- func JWT(params ...any) core.ZodCheck
- func JWTWithAlgorithm(algorithm string, params ...any) core.ZodCheck
- func KSUID(params ...any) core.ZodCheck
- func Length(exact int, params ...any) core.ZodCheck
- func LengthRange(minimum, maximum int, params ...any) core.ZodCheck
- func Lowercase(params ...any) core.ZodCheck
- func Lt(value any, params ...any) core.ZodCheck
- func Lte(value any, params ...any) core.ZodCheck
- func MaxFileSize(maximum int64, params ...any) core.ZodCheck
- func MaxLength(maximum int, params ...any) core.ZodCheck
- func MaxSize(maximum int, params ...any) core.ZodCheck
- func Mime(mimeTypes []string, params ...any) core.ZodCheck
- func MinFileSize(minimum int64, params ...any) core.ZodCheck
- func MinLength(minimum int, params ...any) core.ZodCheck
- func MinSize(minimum int, params ...any) core.ZodCheck
- func MultipleOf(divisor any, params ...any) core.ZodCheck
- func NanoID(params ...any) core.ZodCheck
- func Negative(params ...any) core.ZodCheck
- func NonEmpty(params ...any) core.ZodCheck
- func NonNegative(params ...any) core.ZodCheck
- func NonPositive(params ...any) core.ZodCheck
- func NormalizeCheckParams(params ...any) *core.CheckParams
- func Positive(params ...any) core.ZodCheck
- func PrefixIssues(path any, issues []core.ZodRawIssue) []core.ZodRawIssue
- func Regex(pattern *regexp.Regexp, params ...any) core.ZodCheck
- func Rfc5322Email(params ...any) core.ZodCheck
- func SetBagProperty(schema any, key string, value any)
- func Size(exact int, params ...any) core.ZodCheck
- func SizeRange(minimum, maximum int, params ...any) core.ZodCheck
- func StartsWith(prefix string, params ...any) core.ZodCheck
- func StringGte(minValue string, params ...any) core.ZodCheck
- func StringLte(maxValue string, params ...any) core.ZodCheck
- func ULID(params ...any) core.ZodCheck
- func URL(params ...any) core.ZodCheck
- func URLWithOptions(options validate.URLOptions, params ...any) core.ZodCheck
- func UUID(params ...any) core.ZodCheck
- func UUID6(params ...any) core.ZodCheck
- func UUID7(params ...any) core.ZodCheck
- func UUIDv4(params ...any) core.ZodCheck
- func UnicodeEmail(params ...any) core.ZodCheck
- func Uppercase(params ...any) core.ZodCheck
- func XID(params ...any) core.ZodCheck
- type ISODateTimeOptions
- type ISOTimeOptions
- type ZodCheckCustom
- type ZodCheckCustomDef
- type ZodCheckCustomInternals
- type ZodCheckOverwrite
- type ZodCheckOverwriteDef
- type ZodCheckOverwriteInternals
- type ZodCheckProperty
- type ZodCheckPropertyDef
- type ZodCheckPropertyInternals
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCheckParams ¶ added in v0.3.0
func ApplyCheckParams(def *core.ZodCheckDef, params *core.CheckParams)
ApplyCheckParams applies normalized parameters to check definition
func ApplySchemaParamsToCheck ¶ added in v0.3.0
func ApplySchemaParamsToCheck(def *core.ZodCheckDef, params *core.SchemaParams)
ApplySchemaParamsToCheck applies SchemaParams to a check definition Used for validation checks that support error and abort configuration
func Base64 ¶
Base64 creates a Base64 encoding validation check with JSON Schema support Supports: Base64("invalid base64") or Base64(CheckParams{Error: "invalid base64 encoding"})
func Base64URL ¶
Base64URL creates a Base64URL encoding validation check with JSON Schema support Supports: Base64URL("invalid base64url") or Base64URL(CheckParams{Error: "invalid base64url encoding"})
func BrowserEmail ¶ added in v0.3.0
BrowserEmail creates a browser-compatible email validation check
func CIDRv4 ¶
CIDRv4 creates an IPv4 CIDR notation validation check with JSON Schema support Supports: CIDRv4("invalid CIDR") or CIDRv4(CheckParams{Error: "invalid IPv4 CIDR"})
func CIDRv6 ¶
CIDRv6 creates an IPv6 CIDR notation validation check with JSON Schema support Supports: CIDRv6("invalid CIDR") or CIDRv6(CheckParams{Error: "invalid IPv6 CIDR"})
func CUID ¶
CUID creates a CUID format validation check with JSON Schema support Supports: CUID("invalid CUID") or CUID(CheckParams{Error: "invalid CUID format"})
func CUID2 ¶
CUID2 creates a CUID2 format validation check with JSON Schema support Supports: CUID2("invalid CUID2") or CUID2(CheckParams{Error: "invalid CUID2 format"})
func E164 ¶
E164 creates an E.164 phone number validation check with JSON Schema support Supports: E164("invalid phone") or E164(CheckParams{Error: "invalid E.164 format"})
func Email ¶
Email creates an email format validation check with JSON Schema support Supports: Email("invalid email") or Email(CheckParams{Error: "invalid email format"})
func EmailWithPattern ¶ added in v0.3.0
EmailWithPattern creates an email validation check with custom regex pattern
func Emoji ¶ added in v0.3.1
Emoji creates an emoji validation check with JSON Schema support. Supports: Emoji("invalid emoji") or Emoji(CheckParams{Error: "invalid emoji"})
func Empty ¶
Empty creates an empty validation check with JSON Schema support Supports: Empty("must be empty") or Empty(CheckParams{Error: "value must be empty"})
func EndsWith ¶
EndsWith creates a suffix check with JSON Schema support Supports: EndsWith("suffix", "wrong end") or EndsWith("suffix", CheckParams{Error: "must end with suffix"})
func FileSize ¶ added in v0.3.0
FileSize creates an exact file size validation check Supports: FileSize(1024, "file must be exactly 1KB") or FileSize(1024, CheckParams{Error: "exact size required"})
func GUID ¶
GUID creates a GUID format validation check with JSON Schema support Supports: GUID("invalid GUID") or GUID(CheckParams{Error: "invalid GUID format"})
func Gt ¶
Gt creates a greater than validation check with JSON Schema support Supports: Gt(0, "too small") or Gt(0, CheckParams{Error: "value must be greater than 0"})
func Gte ¶
Gte creates a greater than or equal validation check with JSON Schema support Supports: Gte(0, "too small") or Gte(0, CheckParams{Error: "value must be at least 0"})
func Html5Email ¶ added in v0.3.0
Html5Email creates an HTML5 email validation check
func IPv4 ¶
IPv4 creates an IPv4 address format validation check with JSON Schema support Supports: IPv4("invalid IPv4") or IPv4(CheckParams{Error: "invalid IPv4 address"})
func IPv6 ¶
IPv6 creates an IPv6 address format validation check with JSON Schema support Supports: IPv6("invalid IPv6") or IPv6(CheckParams{Error: "invalid IPv6 address"})
func ISODate ¶
ISODate creates an ISO 8601 date format validation check with JSON Schema support Supports: ISODate("invalid date") or ISODate(CheckParams{Error: "invalid date format"})
func ISODateMax ¶ added in v0.3.0
ISODateMax creates a maximum date validation check Validates that the ISO date is on or before the specified maximum date
func ISODateMin ¶ added in v0.3.0
ISODateMin creates a minimum date validation check Validates that the ISO date is on or after the specified minimum date
func ISODateTime ¶
ISODateTime creates an ISO 8601 datetime format validation check with JSON Schema support Supports: ISODateTime("invalid datetime") or ISODateTime(CheckParams{Error: "invalid datetime format"})
func ISODateTimeWithOptions ¶ added in v0.3.0
func ISODateTimeWithOptions(options ISODateTimeOptions, params ...any) core.ZodCheck
ISODateTimeWithOptions creates an ISO 8601 datetime validation check with options Supports: ISODateTimeWithOptions(options, "invalid datetime") or ISODateTimeWithOptions(options, CheckParams{Error: "invalid datetime"})
func ISODuration ¶
ISODuration creates an ISO 8601 duration validation check with JSON Schema support Supports: ISODuration("invalid duration") or ISODuration(CheckParams{Error: "invalid ISO duration"})
func ISOTime ¶
ISOTime creates an ISO 8601 time validation check with JSON Schema support Supports: ISOTime("invalid time") or ISOTime(CheckParams{Error: "invalid ISO time"})
func ISOTimeWithOptions ¶ added in v0.3.0
func ISOTimeWithOptions(options ISOTimeOptions, params ...any) core.ZodCheck
ISOTimeWithOptions creates an ISO 8601 time validation check with configuration options Supports: ISOTimeWithOptions(options, "invalid time") or ISOTimeWithOptions(options, CheckParams{Error: "invalid ISO time"})
func Includes ¶
Includes creates a substring inclusion check with JSON Schema support Supports: Includes("test", "must contain test") or Includes("test", CheckParams{Error: "missing required substring"})
func JSON ¶ added in v0.3.0
JSON creates a JSON format validation check with JSON Schema support Supports: JSON("invalid JSON") or JSON(CheckParams{Error: "invalid JSON"})
func JWT ¶
JWT creates a JWT token validation check with JSON Schema support Supports: JWT("invalid JWT") or JWT(CheckParams{Error: "invalid JWT token"})
func JWTWithAlgorithm ¶ added in v0.3.0
JWTWithAlgorithm creates a JWT token validation check with algorithm constraint Supports: JWTWithAlgorithm("HS256", "invalid JWT") or JWTWithAlgorithm("RS256", CheckParams{Error: "invalid JWT token"})
func KSUID ¶
KSUID creates a KSUID format validation check with JSON Schema support Supports: KSUID("invalid KSUID") or KSUID(CheckParams{Error: "invalid KSUID format"})
func Length ¶
Length creates an exact length validation check with JSON Schema support Supports: Length(10, "must be exactly 10 chars") or Length(10, CheckParams{Error: "exact length required"})
func LengthRange ¶
LengthRange creates a length range validation check with JSON Schema support Supports: LengthRange(3, 10, "length must be 3-10") or LengthRange(3, 10, CheckParams{Error: "invalid length range"})
func Lowercase ¶
Lowercase creates a lowercase format check with JSON Schema support Supports: Lowercase("must be lowercase") or Lowercase(CheckParams{Error: "only lowercase letters allowed"})
func Lt ¶
Lt creates a less than validation check with JSON Schema support Supports: Lt(10, "too big") or Lt(10, CheckParams{Error: "value must be less than 10"})
func Lte ¶
Lte creates a less than or equal validation check with JSON Schema support Supports: Lte(10, "too big") or Lte(10, CheckParams{Error: "value must be at most 10"})
func MaxFileSize ¶ added in v0.3.0
MaxFileSize creates a maximum file size validation check Supports: MaxFileSize(5242880, "file too large") or MaxFileSize(5242880, CheckParams{Error: "maximum size exceeded"})
func MaxLength ¶
MaxLength creates a maximum length validation check with JSON Schema support Supports: MaxLength(5, "too long") or MaxLength(5, CheckParams{Error: "too long"})
func MaxSize ¶
MaxSize creates a maximum size validation check with JSON Schema support Supports: MaxSize(100, "too many items") or MaxSize(100, CheckParams{Error: "size limit exceeded"})
func Mime ¶ added in v0.2.1
Mime creates a MIME type validation check for file schemas Supports: Mime([]string{"text/plain", "application/json"}, "invalid mime")
func MinFileSize ¶ added in v0.3.0
MinFileSize creates a minimum file size validation check Supports: MinFileSize(1024, "file too small") or MinFileSize(1024, CheckParams{Error: "minimum size required"})
func MinLength ¶
MinLength creates a minimum length validation check with JSON Schema support Supports: MinLength(3, "too short") or MinLength(3, CheckParams{Error: "too short"})
func MinSize ¶
MinSize creates a minimum size validation check with JSON Schema support Supports: MinSize(1, "cannot be empty") or MinSize(1, CheckParams{Error: "minimum size required"})
func MultipleOf ¶
MultipleOf creates a multiple of validation check with JSON Schema support Supports: MultipleOf(5, "not divisible") or MultipleOf(5, CheckParams{Error: "must be multiple of 5"})
func NanoID ¶
NanoID creates a NanoID format validation check with JSON Schema support Supports: NanoID("invalid NanoID") or NanoID(CheckParams{Error: "invalid NanoID format"})
func Negative ¶
Negative creates a negative number validation check (less than zero) Supports: Negative("must be negative") or Negative(CheckParams{Error: "value must be negative"})
func NonEmpty ¶
NonEmpty creates a non-empty validation check with JSON Schema support Supports: NonEmpty("cannot be empty") or NonEmpty(CheckParams{Error: "value required"})
func NonNegative ¶
NonNegative creates a non-negative number validation check (greater than or equal to zero) Supports: NonNegative("cannot be negative") or NonNegative(CheckParams{Error: "value cannot be negative"})
func NonPositive ¶
NonPositive creates a non-positive number validation check (less than or equal to zero) Supports: NonPositive("cannot be positive") or NonPositive(CheckParams{Error: "value cannot be positive"})
func NormalizeCheckParams ¶ added in v0.3.0
func NormalizeCheckParams(params ...any) *core.CheckParams
NormalizeCheckParams standardizes check parameters from various input formats Supports: string (shorthand) | core.SchemaParams (detailed)
func Positive ¶
Positive creates a positive number validation check (greater than zero) Supports: Positive("must be positive") or Positive(CheckParams{Error: "value must be positive"})
func PrefixIssues ¶
func PrefixIssues(path any, issues []core.ZodRawIssue) []core.ZodRawIssue
PrefixIssues adds path prefix to validation issues for nested object validation This utility function is used by property validation checks
func Regex ¶
Regex creates a regex pattern check with JSON Schema support Supports: Regex(pattern, "invalid format") or Regex(pattern, CheckParams{Error: "does not match pattern"})
func Rfc5322Email ¶ added in v0.3.0
Rfc5322Email creates an RFC5322 email validation check
func SetBagProperty ¶ added in v0.3.0
SetBagProperty sets a property in the schema's bag for JSON Schema generation Used to store metadata that will be included in generated JSON Schema
func Size ¶
Size creates an exact size validation check with JSON Schema support Supports: Size(5, "must have exactly 5 items") or Size(5, CheckParams{Error: "exact size required"})
func SizeRange ¶
SizeRange creates a size range validation check with JSON Schema support Supports: SizeRange(1, 100, "size must be 1-100") or SizeRange(1, 100, CheckParams{Error: "invalid size range"})
func StartsWith ¶
StartsWith creates a prefix check with JSON Schema support Supports: StartsWith("prefix", "wrong start") or StartsWith("prefix", CheckParams{Error: "must start with prefix"})
func StringGte ¶ added in v0.3.0
StringGte creates a string greater than or equal validation check Uses lexicographic comparison, perfect for ISO 8601 date/time strings
func StringLte ¶ added in v0.3.0
StringLte creates a string less than or equal validation check Uses lexicographic comparison, perfect for ISO 8601 date/time strings
func ULID ¶
ULID creates a ULID format validation check with JSON Schema support Supports: ULID("invalid ULID") or ULID(CheckParams{Error: "invalid ULID format"})
func URL ¶
URL creates a URL format validation check with JSON Schema support Supports: URL("invalid URL") or URL(CheckParams{Error: "invalid URL format"})
func URLWithOptions ¶ added in v0.3.0
func URLWithOptions(options validate.URLOptions, params ...any) core.ZodCheck
URLWithOptions creates a URL validation check with optional constraints Supports: URLWithOptions(validate.URLOptions{Hostname: hostnameRegex}, "invalid URL")
func UUID ¶
UUID creates a UUID format validation check with JSON Schema support Supports: UUID("invalid UUID") or UUID(CheckParams{Error: "invalid UUID format"})
func UUID6 ¶ added in v0.3.1
UUID6 creates a UUID v6 format validation check. Supports: UUID6("invalid UUIDv6") or UUID6(CheckParams{Error: "invalid UUIDv6"})
func UUID7 ¶ added in v0.3.1
UUID7 creates a UUID v7 format validation check. Supports: UUID7("invalid UUIDv7") or UUID7(CheckParams{Error: "invalid UUIDv7"})
func UUIDv4 ¶ added in v0.3.1
UUIDv4 creates a UUID version 4 format validation check. Supports: UUIDv4("invalid UUIDv4") or UUIDv4(CheckParams{Error: "invalid UUIDv4"})
func UnicodeEmail ¶ added in v0.3.0
UnicodeEmail creates a Unicode email validation check
Types ¶
type ISODateTimeOptions ¶ added in v0.3.0
type ISODateTimeOptions struct {
// Precision specifies number of decimal places for seconds
// If nil, matches any number of decimal places
// If 0 or negative, no decimal places allowed
Precision *int
// Offset if true, allows timezone offsets like +01:00
Offset bool
// Local if true, makes the 'Z' timezone marker optional
Local bool
}
ISODateTimeOptions defines configuration for ISO DateTime validation
type ISOTimeOptions ¶ added in v0.3.0
type ISOTimeOptions struct {
// Precision specifies number of decimal places for seconds
// If nil, matches any number of decimal places
// If 0 or negative, no decimal places allowed
// Special case: -1 means minute precision only (no seconds)
Precision *int
}
ISOTimeOptions contains configuration for ISO Time validation
type ZodCheckCustom ¶
type ZodCheckCustom struct {
Internals *ZodCheckCustomInternals
}
ZodCheckCustom represents custom validation check for user-defined validation logic This check executes user-provided refine or check functions with proper error handling
func NewCustom ¶
func NewCustom[T any](fn any, args ...any) *ZodCheckCustom
NewCustom creates a new custom validation check with user-defined validation logic Uses unified parameter handling following Zod TypeScript v4 pattern
func (*ZodCheckCustom) GetZod ¶
func (z *ZodCheckCustom) GetZod() *core.ZodCheckInternals
GetZod returns the internal check structure for execution
type ZodCheckCustomDef ¶
type ZodCheckCustomDef struct {
core.ZodCheckDef
Type string // Custom check type identifier
Params map[string]any // Additional parameters for custom logic
Fn any // RefineFn or CheckFn function
FnType string // "refine" or "check" function type
}
ZodCheckCustomDef defines custom validation constraint for user-defined validation logic
type ZodCheckCustomInternals ¶
type ZodCheckCustomInternals struct {
core.ZodCheckInternals
Def *ZodCheckCustomDef // Custom check definition
Issc *core.ZodIssueBase // Issue base for error handling
Bag map[string]any // Additional metadata storage
}
ZodCheckCustomInternals contains custom check internal state and validation state
type ZodCheckOverwrite ¶
type ZodCheckOverwrite struct {
Internals *ZodCheckOverwriteInternals
}
ZodCheckOverwrite represents overwrite validation check for value transformation This check modifies the payload value using the provided transformation function
func NewZodCheckOverwrite ¶
func NewZodCheckOverwrite(transform func(any) any, args ...any) *ZodCheckOverwrite
NewZodCheckOverwrite creates a new check that overwrites input with transformed value
func (*ZodCheckOverwrite) GetZod ¶
func (c *ZodCheckOverwrite) GetZod() *core.ZodCheckInternals
GetZod returns the internal check structure for execution
type ZodCheckOverwriteDef ¶
type ZodCheckOverwriteDef struct {
core.ZodCheckDef
Transform func(any) any // Transformation function
}
ZodCheckOverwriteDef defines overwrite validation constraint for value transformation
type ZodCheckOverwriteInternals ¶
type ZodCheckOverwriteInternals struct {
core.ZodCheckInternals
Def *ZodCheckOverwriteDef
}
ZodCheckOverwriteInternals contains overwrite check internal state
type ZodCheckProperty ¶ added in v0.3.0
type ZodCheckProperty struct {
Internals *ZodCheckPropertyInternals
}
ZodCheckProperty represents property validation check for specific object fields This check validates that a specific property of an object matches the given schema
func NewProperty ¶ added in v0.3.0
func NewProperty(property string, schema core.ZodSchema, args ...any) *ZodCheckProperty
NewProperty creates a new property validation check Validates that input[property] matches the provided schema
func (*ZodCheckProperty) GetZod ¶ added in v0.3.0
func (z *ZodCheckProperty) GetZod() *core.ZodCheckInternals
GetZod returns the internal check structure for execution
type ZodCheckPropertyDef ¶ added in v0.3.0
type ZodCheckPropertyDef struct {
core.ZodCheckDef
Property string // Property name to validate
Schema core.ZodSchema // Schema to validate property against
}
ZodCheckPropertyDef defines property validation constraint for specific object fields
type ZodCheckPropertyInternals ¶ added in v0.3.0
type ZodCheckPropertyInternals struct {
core.ZodCheckInternals
Def *ZodCheckPropertyDef // Property check definition
Issc *core.ZodIssueBase // Issue base for error handling
}
ZodCheckPropertyInternals contains property check internal state