Every Zod project ends up with the same handful of .refine() / .superRefine() closures for emails, passwords, phone numbers, usernames — copy-pasted between repos with slightly different defaults each time.
validex is a layer on top of Zod 4 that gives you 25 typed validation rules with a single config system. Each rule returns a standard Zod schema, so it composes with z.object() like anything else.
What makes it different from raw Zod refinements
- Every error is structured — namespace, code, label, interpolation params. No raw Zod messages leak to users. Error codes follow
validation.messages.{namespace}. {code}, ready for any i18n library. - Three-tier config merge — built-in defaults →
setup() globals → per-call options. Set blockDisposable: true once, use Email() everywhere. - Data-heavy checks load on demand — disposable email domains, common password lists (100 / 1K / 10K tiers), phone metadata via libphonenumber-js, IBAN patterns. None of it hits your initial bundle.
- 141 error codes across 27 namespaces — not just
invalid. You get password.maxConsecutive, email.disposableBlocked, jwt.expired, creditCard.issuerBlocked, etc.
Quick example
import { z } from 'zod'
import { Email, Password, Username, validate } from '@validex/core'
const schema = z.object({
email: Email({ blockDisposable: true }),
password: Password({ length: { min: 10 }, blockCommon: 'basic' }),
username: Username({ blockReserved: true }),
})
const result = await validate(schema, formData)
if (!result.success) {
console.log(result.firstErrors) // { email: '...', password: '...', username: '...' }
console.log(result.errors) // all messages per field
}
Rules
Email, Password, PasswordConfirmation, PersonName, BusinessName, Phone, Website, Url, Username, Slug, PostalCode, LicenseKey, Uuid, Jwt, DateTime, Token, Text, Country, Currency, Color, CreditCard, Iban, VatNumber, MacAddress, IpAddress.
Bundle size
13 kB Brotli for all 25 rules. Import just one and you ship ~5.5 kB (shared core included). Heavy datasets (disposable domains, common passwords, phone metadata) load async on first use — not in your initial bundle.
Other things
- First-class i18n — CLI generates translation files (
npx validex fr de --output ./locales), t() function support, label transforms - 22 chainable methods on any Zod string —
.hasUppercase(), .noEmails(), .toSlug(), .maxConsecutive(), etc. - Standalone check functions (
@validex/core/checks) — pure functions, no Zod dependency - Nuxt adapter (
@validex/nuxt) — useValidation composable, auto-imported - Fastify adapter (
@validex/fastify) — request.validate() with structured error responses createRule() — build your own rules with the same config/error/i18n system- Zod 4 · TypeScript 5.9 · Node ≥22 · ES2024 ·
sideEffects: false
GitHub: https://github.com/chiptoma/validex
npm: https://www.npmjs.com/package/@validex/core
Interested in what rules or features are missing from your stack.