Skip to content

isHexColor ​

The isHexColor function checks if a string represents a valid hexadecimal color.

Syntax ​

typescript
isHexColor(hex: string): boolean;

Parameters ​

NameTypeDescription
hexstringString to be checked

Returns ​

TypeDescription
booleanTrue if it is a valid hexadecimal color

Examples ​

typescript
isHexColor("#ff0000");
// => true

isHexColor("#f00");
// => true

isHexColor("rgb(255, 0, 0)");
// => false

Notes ​

  • Accepts short (#fff) and long (#ffffff) formats, with or without alpha channel.

References ​

Released under the MIT License.