feat: support custom required validation messages
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user