Formify Docs

Hex Color

Validate hex color codes in 3-digit, 6-digit, or 8-digit form.

Hex Color

Validates that a value is a hex color code. The leading # is required.

Configuration

Config flagTypeDescription
hexColorbooleanWhen true, requires the value to be a valid hex color code.

With useForm

const form = useForm({
  initialValues: { color: '' },
  validationSchema: {
    color: { hexColor: true },
  },
});

With the V builder

import { V } from 'formify-js';

V.hexColor();

Default message

ScenarioMessage
Value is not a hex colorMust be a valid hex color code

Examples

ValueResult
'#FFF'✅ Valid (3-digit)
'#ffffff'✅ Valid (6-digit)
'#ffffffff'✅ Valid (8-digit with alpha)
'FFF'❌ Invalid (missing #)
'#12345'❌ Invalid (wrong length)

Notes

  • The # prefix is mandatory — 'FFF' fails even though the hex digits are fine.
  • Supports 3, 6, and 8 digit forms; digits are case-insensitive.

On this page