ZIP / Postal Code
Validate US ZIP codes, with optional ZIP+4 support.
Validates that a value is a US ZIP code. Both the 5-digit form and the ZIP+4 extended form are accepted.
| Config flag | Type | Description |
|---|
zip | boolean | When true, requires the value to be a valid US ZIP code. |
const form = useForm({
initialValues: { postalCode: '' },
validationSchema: {
postalCode: { zip: true },
},
});
import { V } from 'formify-js';
V.zip();
| Scenario | Message |
|---|
| Value is not a valid ZIP code | Must be a valid ZIP code |
| Value | Result |
|---|
'10001' | ✅ Valid |
'10001-4321' | ✅ Valid (ZIP+4) |
'1000' | ❌ Invalid (too short) |
'10A01' | ❌ Invalid (letters) |
- ZIP+4 (
12345-6789) is accepted without any extra configuration.
- This validator targets US ZIP codes only. For other countries' postal codes, use the
pattern validator with the appropriate regex.