Hex Color
Validate hex color codes in 3-digit, 6-digit, or 8-digit form.
Validates that a value is a hex color code. The leading # is required.
| Config flag | Type | Description |
|---|
hexColor | boolean | When true, requires the value to be a valid hex color code. |
const form = useForm({
initialValues: { color: '' },
validationSchema: {
color: { hexColor: true },
},
});
import { V } from 'formify-js';
V.hexColor();
| Scenario | Message |
|---|
| Value is not a hex color | Must be a valid hex color code |
| Value | Result |
|---|
'#FFF' | ✅ Valid (3-digit) |
'#ffffff' | ✅ Valid (6-digit) |
'#ffffffff' | ✅ Valid (8-digit with alpha) |
'FFF' | ❌ Invalid (missing #) |
'#12345' | ❌ Invalid (wrong length) |
- The
# prefix is mandatory — 'FFF' fails even though the hex digits are fine.
- Supports 3, 6, and 8 digit forms; digits are case-insensitive.