Hex
Validate hexadecimal strings without a leading
Validates that a value is a hexadecimal string — digits 0-9 and letters a-f only. Unlike hexColor, no # prefix is expected.
| Config flag | Type | Description |
|---|
hex | boolean | When true, requires the value to be valid hexadecimal. |
const form = useForm({
initialValues: { value: '' },
validationSchema: {
value: { hex: true },
},
});
import { V } from 'formify-js';
V.hex();
| Scenario | Message |
|---|
| Non-hex characters present | Must be valid hexadecimal |
| Value | Result |
|---|
'1A2b3C' | ✅ Valid |
'deadbeef' | ✅ Valid |
'0xFF' | ❌ Invalid (0x prefix not allowed) |
'#fff' | ❌ Invalid (# not allowed) |
'hello' | ❌ Invalid (l and o are not hex digits) |
- Case-insensitive:
'ABCDEF' and 'abcdef' both pass.
- For color codes with the
# prefix, use hexColor instead.