Max
Enforce a maximum numeric value.
Max
Validates that a numeric value is at most a given maximum. Works with numbers and numeric strings.
Configuration
| Config flag | Type | Description |
|---|---|---|
max | number | Maximum accepted value. |
max | [number, string] | Tuple form — the maximum plus a custom message. |
With useForm
const form = useForm({
initialValues: { guests: '' },
validationSchema: {
guests: { max: 10 },
},
});With a custom message:
guests: { max: [10, 'No more than 10 guests'] }With the V builder
import { V } from 'formify-js';
V.max(10);Default message
| Scenario | Message |
|---|---|
| Value is above the maximum | Must be at most 10 (the number reflects your value) |
Examples
| Value | Rule | Result |
|---|---|---|
'10' | max: 10 | ✅ Valid (inclusive) |
'10.5' | max: 10 | ❌ Invalid |
100 | max: 50 | ❌ Invalid |
Notes
- The check is inclusive: a value of exactly
10passesmax: 10. - Non-numeric values fail the comparison — pair with
numericorintegerfor clearer errors. - Use
betweento constrain both ends at once.