Min Length
Enforce a minimum string length.
Min Length
Validates that a string is at least a given number of characters long.
Configuration
| Config flag | Type | Description |
|---|---|---|
minLength | number | Minimum number of characters. |
minLength | [number, string] | Tuple form — the length plus a custom message. |
With useForm
const form = useForm({
initialValues: { name: '' },
validationSchema: {
name: { minLength: 3 },
},
});With a custom message:
name: { minLength: [3, 'At least {min} characters'] }With the V builder
import { V } from 'formify-js';
V.minLength(3);Default message
| Scenario | Message |
|---|---|
| Value is shorter than the minimum | Must be at least 3 characters (the number reflects your value) |
Examples
| Value | Rule | Result |
|---|---|---|
'ab' | minLength: 3 | ❌ Invalid |
'abc' | minLength: 3 | ✅ Valid |
'abcd' | minLength: 3 | ✅ Valid |
Notes
- The check is inclusive: a value of exactly
3characters passesminLength: 3. - Emoji count as single characters in JavaScript string length.
- Combine with
maxLengthto define an exact allowed range.