Skip to content

Form Validation

WELD uses Zod for all validation. The same schema validates the form AND the API response — one source of truth.

Pass a Zod schema to useForm. Validation runs on blur and on submit.

const schema = z.object({
name: z.string().min(2, 'Name must be at least 2 characters'),
email: z.string().email('Invalid email address'),
age: z.number().min(18, 'Must be 18 or older'),
password: z.string()
.min(8, 'At least 8 characters')
.regex(/[A-Z]/, 'Must contain an uppercase letter'),
})
const form = useForm({ initialValues: {...}, schema, onSubmit })

For standalone inputs outside a form:

<Weld.Input
type="email"
label="Email"
schema={z.string().email()}
placeholder="you@example.com"
/>

Errors appear below the field after blur, styled automatically.

const form = useForm({
initialValues,
schema,
validateOnChange: true, // default: false
onSubmit,
})

Set field errors programmatically (e.g. from API response):

form.setError('email', 'This email is already taken')