Skip to main content

isValidHex

The isValidHex function checks if the input string is a valid Hex color format. It supports both shorthand (#RGB) and standard (#RRGGBB) hex formats.

Syntax

isValidHex(color: string): boolean

Parameters

  • color (string): The input color string.

Returns

  • boolean: True if the input is a valid hex color, false otherwise.

Example

import { isValidHex } from 'colore-js';

console.log(isValidHex('#ff0000')); // Output: true
console.log(isValidHex('#f00')); // Output: true
console.log(isValidHex('#ff00000')); // Output: false
console.log(isValidHex('red')); // Output: false

Usage

The isValidHex function is used to validate whether a given color string conforms to the Hex color format. This can be useful for input validation in color manipulation and design applications.