Validation
Messages & modes
Customize error messages and control when validation runs.
Custom messages
Every built-in rule accepts either a bare value or a { value, message } object:
validators: {
required: { value: true, message: 'We need your name' },
minLength: { value: 2, message: 'That seems too short' },
pattern: { value: /^[A-Z]/, message: 'Start with a capital letter' },
}Without a custom message, a sensible default is used.
Validation modes
The validation mode controls when a field validates:
| Prop | Type | Default | Description |
|---|---|---|---|
| 'onChange' | mode | — | Validate on every change. Most immediate feedback. |
| 'onBlur' | mode | — | Validate when the field loses focus. |
| 'onSubmit' | mode | — | Validate only when the form is submitted. |
| 'all' | mode | — | Validate on both change and blur. |
Regardless of mode, all visible fields are validated on submit before onSubmit runs.
The submit gate
The default footer keeps the submit button disabled until the form is dirty and valid,
and disables it while submitting. You can build your own footer using
useFormState if you need different behavior.