Starts With
Require a value to begin with a specific prefix.
Starts With
Validates that a value starts with a given prefix string.
Configuration
| Config flag | Type | Description |
|---|---|---|
startsWith | string | The required prefix. |
startsWith | [string, string] | Tuple form — the prefix plus a custom message. |
With useForm
const form = useForm({
initialValues: { orderId: '' },
validationSchema: {
orderId: { startsWith: 'ORD-' },
},
});With a custom message:
orderId: { startsWith: ['ORD-', 'Order IDs start with ORD-'] }With the V builder
import { V } from 'formify-js';
V.startsWith('ORD-');Default message
| Scenario | Message |
|---|---|
| Value does not start with the prefix | Must start with "ORD-" (the message names your prefix) |
Examples
| Value | Rule | Result |
|---|---|---|
'ORD-123' | startsWith: 'ORD-' | ✅ Valid |
'123-ORD' | startsWith: 'ORD-' | ❌ Invalid |
Notes
- The check is case-sensitive:
'ord-123'fails when the prefix is'ORD-'. - Combine with
patternor other rules when the remainder of the value also has a format.