checks

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 12 Imported by: 0

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

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

func Base64(params ...any) core.ZodCheck

Base64 creates a Base64 encoding validation check with JSON Schema support Supports: Base64("invalid base64") or Base64(CheckParams{Error: "invalid base64 encoding"})

func Base64URL

func Base64URL(params ...any) core.ZodCheck

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

func BrowserEmail(params ...any) core.ZodCheck

BrowserEmail creates a browser-compatible email validation check

func CIDRv4

func CIDRv4(params ...any) core.ZodCheck

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

func CIDRv6(params ...any) core.ZodCheck

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

func CUID(params ...any) core.ZodCheck

CUID creates a CUID format validation check with JSON Schema support Supports: CUID("invalid CUID") or CUID(CheckParams{Error: "invalid CUID format"})

func CUID2

func CUID2(params ...any) core.ZodCheck

CUID2 creates a CUID2 format validation check with JSON Schema support Supports: CUID2("invalid CUID2") or CUID2(CheckParams{Error: "invalid CUID2 format"})

func E164

func E164(params ...any) core.ZodCheck

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

func Email(params ...any) core.ZodCheck

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

func EmailWithPattern(pattern *regexp.Regexp, params ...any) core.ZodCheck

EmailWithPattern creates an email validation check with custom regex pattern

func Emoji added in v0.3.1

func Emoji(params ...any) core.ZodCheck

Emoji creates an emoji validation check with JSON Schema support. Supports: Emoji("invalid emoji") or Emoji(CheckParams{Error: "invalid emoji"})

func Empty

func Empty(params ...any) core.ZodCheck

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

func EndsWith(suffix string, params ...any) core.ZodCheck

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

func FileSize(expected int64, params ...any) core.ZodCheck

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

func GUID(params ...any) core.ZodCheck

GUID creates a GUID format validation check with JSON Schema support Supports: GUID("invalid GUID") or GUID(CheckParams{Error: "invalid GUID format"})

func Gt

func Gt(value any, params ...any) core.ZodCheck

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

func Gte(value any, params ...any) core.ZodCheck

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

func Html5Email(params ...any) core.ZodCheck

Html5Email creates an HTML5 email validation check

func IPv4

func IPv4(params ...any) core.ZodCheck

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

func IPv6(params ...any) core.ZodCheck

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

func ISODate(params ...any) core.ZodCheck

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

func ISODateMax(maxDate string, params ...any) core.ZodCheck

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

func ISODateMin(minDate string, params ...any) core.ZodCheck

ISODateMin creates a minimum date validation check Validates that the ISO date is on or after the specified minimum date

func ISODateTime

func ISODateTime(params ...any) core.ZodCheck

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

func ISODuration(params ...any) core.ZodCheck

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

func ISOTime(params ...any) core.ZodCheck

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

func Includes(substring string, params ...any) core.ZodCheck

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

func JSON(params ...any) core.ZodCheck

JSON creates a JSON format validation check with JSON Schema support Supports: JSON("invalid JSON") or JSON(CheckParams{Error: "invalid JSON"})

func JWT

func JWT(params ...any) core.ZodCheck

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

func JWTWithAlgorithm(algorithm string, params ...any) core.ZodCheck

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

func KSUID(params ...any) core.ZodCheck

KSUID creates a KSUID format validation check with JSON Schema support Supports: KSUID("invalid KSUID") or KSUID(CheckParams{Error: "invalid KSUID format"})

func Length

func Length(exact int, params ...any) core.ZodCheck

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

func LengthRange(minimum, maximum int, params ...any) core.ZodCheck

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

func Lowercase(params ...any) core.ZodCheck

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

func Lt(value any, params ...any) core.ZodCheck

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

func Lte(value any, params ...any) core.ZodCheck

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

func MaxFileSize(maximum int64, params ...any) core.ZodCheck

MaxFileSize creates a maximum file size validation check Supports: MaxFileSize(5242880, "file too large") or MaxFileSize(5242880, CheckParams{Error: "maximum size exceeded"})

func MaxLength

func MaxLength(maximum int, params ...any) core.ZodCheck

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

func MaxSize(maximum int, params ...any) core.ZodCheck

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

func Mime(mimeTypes []string, params ...any) core.ZodCheck

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

func MinFileSize(minimum int64, params ...any) core.ZodCheck

MinFileSize creates a minimum file size validation check Supports: MinFileSize(1024, "file too small") or MinFileSize(1024, CheckParams{Error: "minimum size required"})

func MinLength

func MinLength(minimum int, params ...any) core.ZodCheck

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

func MinSize(minimum int, params ...any) core.ZodCheck

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

func MultipleOf(divisor any, params ...any) core.ZodCheck

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

func NanoID(params ...any) core.ZodCheck

NanoID creates a NanoID format validation check with JSON Schema support Supports: NanoID("invalid NanoID") or NanoID(CheckParams{Error: "invalid NanoID format"})

func Negative

func Negative(params ...any) core.ZodCheck

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

func NonEmpty(params ...any) core.ZodCheck

NonEmpty creates a non-empty validation check with JSON Schema support Supports: NonEmpty("cannot be empty") or NonEmpty(CheckParams{Error: "value required"})

func NonNegative

func NonNegative(params ...any) core.ZodCheck

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

func NonPositive(params ...any) core.ZodCheck

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

func Positive(params ...any) core.ZodCheck

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

func Regex(pattern *regexp.Regexp, params ...any) core.ZodCheck

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

func Rfc5322Email(params ...any) core.ZodCheck

Rfc5322Email creates an RFC5322 email validation check

func SetBagProperty added in v0.3.0

func SetBagProperty(schema any, key string, value any)

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

func Size(exact int, params ...any) core.ZodCheck

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

func SizeRange(minimum, maximum int, params ...any) core.ZodCheck

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

func StartsWith(prefix string, params ...any) core.ZodCheck

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

func StringGte(minValue string, params ...any) core.ZodCheck

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

func StringLte(maxValue string, params ...any) core.ZodCheck

StringLte creates a string less than or equal validation check Uses lexicographic comparison, perfect for ISO 8601 date/time strings

func ULID

func ULID(params ...any) core.ZodCheck

ULID creates a ULID format validation check with JSON Schema support Supports: ULID("invalid ULID") or ULID(CheckParams{Error: "invalid ULID format"})

func URL

func URL(params ...any) core.ZodCheck

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

func UUID(params ...any) core.ZodCheck

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

func UUID6(params ...any) core.ZodCheck

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

func UUID7(params ...any) core.ZodCheck

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

func UUIDv4(params ...any) core.ZodCheck

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

func UnicodeEmail(params ...any) core.ZodCheck

UnicodeEmail creates a Unicode email validation check

func Uppercase

func Uppercase(params ...any) core.ZodCheck

Uppercase creates an uppercase format check with JSON Schema support Supports: Uppercase("must be uppercase") or Uppercase(CheckParams{Error: "only uppercase letters allowed"})

func XID

func XID(params ...any) core.ZodCheck

XID creates an XID format validation check with JSON Schema support Supports: XID("invalid XID") or XID(CheckParams{Error: "invalid XID format"})

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL