Confirm
Require a field to match the value of another field.
Confirm
Validates that a value matches the value of another field in the same form. The classic use case is a "confirm password" field.
Configuration
| Config flag | Type | Description |
|---|---|---|
confirm | string | The name of the field whose value must match. |
confirm | [string, string] | Tuple form — the target field plus a custom message. |
With useForm
const form = useForm({
initialValues: { password: '', confirmPassword: '' },
validationSchema: {
confirmPassword: { confirm: 'password' },
},
});With a custom message — and re-validate whenever the target field changes:
confirmPassword: {
confirm: ['password', 'Passwords do not match'],
deps: ['password'],
}With the V builder
import { V } from 'formify-js';
V.confirm('password');Default message
| Scenario | Message |
|---|---|
| Values do not match | Does not match password (the message names the target field) |
Notes
- The referenced field must exist in
initialValues; the check reads the current value of that field on each validation run. - The target field itself should carry its own rules (e.g.
minLength);confirmonly checks equality. - Pair with
getFieldValues/ field-levelvalidatefunctions if you need more complex cross-field logic.