feat: support custom required validation messages

This commit is contained in:
2026-07-13 20:34:36 +05:30
parent b273e30c2f
commit 7a1c6c0041
58 changed files with 169 additions and 93 deletions
+3 -2
View File
@@ -35,6 +35,7 @@ import { v } from "@wrnexus/validation";
Every field schema is chainable and shares these base methods:
- `min(n, message?)` / `max(n, message?)` — for strings, bounds the length; for numbers, bounds the value.
- `required(message?)` — require a non-empty value and optionally replace the default `"Required"` message on both server and browser validation.
- `optional()` — an empty/missing value passes instead of erroring `"Required"`.
- `label(text)` — human label carried into the descriptor.
- `default(value)` — value substituted when the field is absent (implies `optional`).
@@ -121,8 +122,8 @@ Define a schema and validate an API body:
import { v, parseBody } from "@wrnexus/validation";
export const signupSchema = v.object({
email: v.string().trim().email(),
password: v.string().min(8).max(200),
email: v.string().required("Enter your email address").trim().email(),
password: v.string().required("Enter your password").min(8).max(200),
age: v.number().integer().min(13).max(120).optional(),
role: v.string().oneOf(["user", "admin"]).default("user"),
agree: v.boolean(),