checks

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package checks provides validation check factories for the GoZod validation library. It implements Zod v4-compatible check creation with JSON Schema metadata support.

Package checks provides validation check factories and utilities for creating reusable validation rules that can be attached to schemas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCheckParams added in v0.3.0

func ApplyCheckParams(def *core.ZodCheckDef, cp *core.CheckParams)

ApplyCheckParams applies normalized parameters to a check definition.

func ApplySchemaParamsToCheck added in v0.3.0

func ApplySchemaParamsToCheck(def *core.ZodCheckDef, sp *core.SchemaParams)

ApplySchemaParamsToCheck applies SchemaParams to a check definition.

func Base64

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

Base64 creates a Base64 encoding validation check.

func Base64URL

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

Base64URL creates a Base64URL encoding validation check.

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.

func CIDRv6

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

CIDRv6 creates an IPv6 CIDR notation validation check.

func CUID

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

CUID creates a CUID format validation check.

func CUID2

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

CUID2 creates a CUID2 format validation check.

func Describe added in v0.5.4

func Describe(description string) core.ZodCheck

Describe creates a no-op check that registers a description in the global registry when attached to a schema.

Example:

schema := gozod.String().Check(gozod.Describe("User email"))

func E164

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

E164 creates an E.164 phone number validation check.

func Email

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

Email creates an email format validation check.

func EmailWithPattern added in v0.3.0

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

EmailWithPattern creates an email validation check with a custom regex pattern.

func Emoji added in v0.3.1

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

Emoji creates an emoji validation check.

func Empty

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

Empty creates an empty validation check (exact length 0).

func EndsWith

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

EndsWith creates a suffix validation check.

func FileSize added in v0.3.0

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

FileSize creates an exact file size validation check.

func GUID

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

GUID creates a GUID format validation check.

func Gt

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

Gt creates a greater-than validation check.

func Gte

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

Gte creates a greater-than-or-equal validation check.

func HTML5Email added in v0.6.0

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

HTML5Email creates an HTML5 email validation check.

func Hex added in v0.5.4

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

Hex creates a hexadecimal string validation check.

func Hostname added in v0.5.4

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

Hostname creates a DNS hostname validation check.

func IPv4

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

IPv4 creates an IPv4 address format validation check.

func IPv6

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

IPv6 creates an IPv6 address format validation check.

func ISODate

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

ISODate creates an ISO 8601 date format validation check.

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.

func ISODateTimeWithOptions added in v0.3.0

func ISODateTimeWithOptions(options validate.ISODateTimeOptions, params ...any) core.ZodCheck

ISODateTimeWithOptions creates an ISO 8601 datetime validation check with options.

func ISODuration

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

ISODuration creates an ISO 8601 duration validation check.

func ISOTime

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

ISOTime creates an ISO 8601 time validation check.

func ISOTimeWithOptions added in v0.3.0

func ISOTimeWithOptions(options validate.ISOTimeOptions, params ...any) core.ZodCheck

ISOTimeWithOptions creates an ISO 8601 time validation check with configuration. Uses self-reference to attach Inst on the created issue.

func Includes

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

Includes creates a substring inclusion check.

func JSON added in v0.3.0

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

JSON creates a JSON format validation check.

func JWT

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

JWT creates a JWT token validation check.

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.

func JWTWithOptions added in v0.5.3

func JWTWithOptions(options validate.JWTOptions, params ...any) core.ZodCheck

JWTWithOptions creates a JWT token validation check with full configuration.

func KSUID

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

KSUID creates a KSUID format validation check.

func Length

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

Length creates an exact length validation check.

func LengthRange

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

LengthRange creates a length range validation check.

func Lowercase

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

Lowercase creates a lowercase format validation check.

func Lt

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

Lt creates a less-than validation check.

func Lte

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

Lte creates a less-than-or-equal validation check.

func MAC added in v0.5.3

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

MAC creates a MAC address validation check with default colon delimiter.

func MACWithDelimiter added in v0.5.3

func MACWithDelimiter(delimiter string, params ...any) core.ZodCheck

MACWithDelimiter creates a MAC address validation check with a custom delimiter.

func MACWithOptions added in v0.5.3

func MACWithOptions(options validate.MACOptions, params ...any) core.ZodCheck

MACWithOptions creates a MAC address validation check with full configuration.

func MD5 added in v0.5.4

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

MD5 creates an MD5 hash validation check (32 hex chars).

func MaxFileSize added in v0.3.0

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

MaxFileSize creates a maximum file size validation check.

func MaxLength

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

MaxLength creates a maximum length validation check.

func MaxSize

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

MaxSize creates a maximum size validation check.

func Meta added in v0.5.4

func Meta(metadata core.GlobalMeta) core.ZodCheck

Meta creates a no-op check that merges metadata into the global registry when attached to a schema.

Example:

schema := gozod.Number().Check(gozod.Meta(gozod.GlobalMeta{
    Title: "Age",
    Description: "User's age",
}))

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.

func MinFileSize added in v0.3.0

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

MinFileSize creates a minimum file size validation check.

func MinLength

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

MinLength creates a minimum length validation check.

func MinSize

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

MinSize creates a minimum size validation check.

func MultipleOf

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

MultipleOf creates a multiple-of validation check.

func NanoID

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

NanoID creates a NanoID format validation check.

func Negative

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

Negative creates a check that the value is less than zero.

func NonEmpty

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

NonEmpty creates a non-empty validation check (minimum length 1).

func NonNegative

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

NonNegative creates a check that the value is greater than or equal to zero.

func NonPositive

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

NonPositive creates a check that the value is less than or equal to zero.

func NormalizeCheckParams added in v0.3.0

func NormalizeCheckParams(params ...any) *core.CheckParams

NormalizeCheckParams standardizes check parameters from various input formats. It accepts a string shorthand or core.SchemaParams.

func Positive

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

Positive creates a check that the value is greater than zero.

func PrefixIssues

func PrefixIssues(path any, iss []core.ZodRawIssue) []core.ZodRawIssue

PrefixIssues prepends a path segment to all issues for nested validation.

func RFC5322Email added in v0.6.0

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

RFC5322Email creates an RFC 5322 email validation check.

func Regex

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

Regex creates a regex pattern validation check.

func SHA1 added in v0.5.4

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

SHA1 creates a SHA-1 hash validation check (40 hex chars).

func SHA256 added in v0.5.4

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

SHA256 creates a SHA-256 hash validation check (64 hex chars).

func SHA384 added in v0.5.4

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

SHA384 creates a SHA-384 hash validation check (96 hex chars).

func SHA512 added in v0.5.4

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

SHA512 creates a SHA-512 hash validation check (128 hex chars).

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.

func Size

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

Size creates an exact size validation check.

func SizeRange

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

SizeRange creates a size range validation check.

func StartsWith

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

StartsWith creates a prefix validation check.

func StringGte added in v0.3.0

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

StringGte creates a string greater-than-or-equal check using lexicographic comparison, suitable 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 check using lexicographic comparison, suitable for ISO 8601 date/time strings.

func ULID

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

ULID creates a ULID format validation check.

func URL

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

URL creates a URL format validation check.

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.

func UUID

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

UUID creates a UUID format validation check.

func UUID6 added in v0.3.1

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

UUID6 creates a UUID v6 format validation check.

func UUID7 added in v0.3.1

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

UUID7 creates a UUID v7 format validation check.

func UUIDv4 added in v0.3.1

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

UUIDv4 creates a UUID version 4 format validation check.

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 validation check.

func XID

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

XID creates an XID format validation check.

Types

type ZodCheckCustom

type ZodCheckCustom struct {
	Internals *ZodCheckCustomInternals
}

ZodCheckCustom represents a custom validation check.

func NewCustom

func NewCustom[T any](fn any, args ...any) *ZodCheckCustom

NewCustom creates a custom validation check with user-defined logic.

func (*ZodCheckCustom) Zod added in v0.6.0

Zod returns the internal check structure for execution.

type ZodCheckCustomDef

type ZodCheckCustomDef struct {
	core.ZodCheckDef
	Type   string         // check type identifier
	Params map[string]any // additional parameters
	Fn     any            // RefineFn or CheckFn
	FnType string         // "refine" or "check"
}

ZodCheckCustomDef defines a custom validation constraint.

type ZodCheckCustomInternals

type ZodCheckCustomInternals struct {
	core.ZodCheckInternals
	Def  *ZodCheckCustomDef
	Issc *core.ZodIssueBase
	Bag  map[string]any
}

ZodCheckCustomInternals contains custom check internal state.

type ZodCheckDescribe added in v0.5.4

type ZodCheckDescribe struct {
	// contains filtered or unexported fields
}

ZodCheckDescribe is a no-op check that attaches a description to the schema's metadata in the global registry.

func (*ZodCheckDescribe) Zod added in v0.6.0

Zod returns the internal check structure for execution.

type ZodCheckMeta added in v0.5.4

type ZodCheckMeta struct {
	// contains filtered or unexported fields
}

ZodCheckMeta is a no-op check that attaches arbitrary metadata to the schema's metadata in the global registry.

func (*ZodCheckMeta) Zod added in v0.6.0

Zod returns the internal check structure for execution.

type ZodCheckOverwrite

type ZodCheckOverwrite struct {
	Internals *ZodCheckOverwriteInternals
}

ZodCheckOverwrite represents a check that replaces the payload value.

func NewZodCheckOverwrite

func NewZodCheckOverwrite(transform func(any) any, args ...any) *ZodCheckOverwrite

NewZodCheckOverwrite creates a check that overwrites input with a transformed value.

func (*ZodCheckOverwrite) Zod added in v0.6.0

Zod returns the internal check structure for execution.

type ZodCheckOverwriteDef

type ZodCheckOverwriteDef struct {
	core.ZodCheckDef
	Transform func(any) any
}

ZodCheckOverwriteDef defines a value transformation constraint.

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 validates a specific object property against a schema.

func NewProperty added in v0.3.0

func NewProperty(property string, schema core.ZodSchema, args ...any) *ZodCheckProperty

NewProperty creates a property validation check that validates input[property] against the provided schema.

func (*ZodCheckProperty) Zod added in v0.6.0

Zod returns the internal check structure for execution.

type ZodCheckPropertyDef added in v0.3.0

type ZodCheckPropertyDef struct {
	core.ZodCheckDef
	Property string
	Schema   core.ZodSchema
}

ZodCheckPropertyDef defines a property validation constraint.

type ZodCheckPropertyInternals added in v0.3.0

type ZodCheckPropertyInternals struct {
	core.ZodCheckInternals
	Def  *ZodCheckPropertyDef
	Issc *core.ZodIssueBase
}

ZodCheckPropertyInternals contains property check internal state.

Jump to

Keyboard shortcuts

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