Skip to content

hex

Validates that a field contains a hexadecimal number.

Options

OptionTypeDefaultDescription
messagestringlocale defaultCustom error message

Playground

Valid values

ValueNotes
"FF5733"Valid hex digits
"0a1b2c"Lowercase hex
"0"Single digit

Invalid values

ValueReason
"GG5733"G is not a hex digit
"#FF5733"Hash prefix is not allowed

Notes

  • Empty string ("") always returns valid: true. Combine with notEmpty to require a value.
  • For CSS color validation (with # prefix, rgb(), etc.), use color instead.

Released under the MIT License.