Colore JS

Search documentation

Find a function or jump to a section.
v1.4.4

isValidHex

Legacy documentation for Colore JS 1.4.4.View v2 docs

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.