Max Length
Enforce a maximum string length.
Max Length
Validates that a string is at most a given number of characters long.
Configuration
| Config flag | Type | Description |
|---|---|---|
maxLength | number | Maximum number of characters. |
maxLength | [number, string] | Tuple form — the length plus a custom message. |
With useForm
const form = useForm({
initialValues: { bio: '' },
validationSchema: {
bio: { maxLength: 160 },
},
});With a custom message:
bio: { maxLength: [160, 'At most {max} characters'] }With the V builder
import { V } from 'formify-js';
V.maxLength(160);Default message
| Scenario | Message |
|---|---|
| Value is longer than the maximum | Must be at most 160 characters (the number reflects your value) |
Examples
| Value | Rule | Result |
|---|---|---|
'abc' | maxLength: 3 | ✅ Valid |
'abcd' | maxLength: 3 | ❌ Invalid |
Notes
- The check is inclusive: a value of exactly
3characters passesmaxLength: 3. - Combine with
minLengthto define an exact allowed range.