Skip to main content

Function: isHexColor()

isHexColor(str): Option<string>

Defined in: string/validators/index.ts:198

Validates if a string is a valid hexadecimal color.

Supports 3, 6, and 8 character hex colors with optional # prefix.

Parameters

str

string

The string to validate

Returns

Option<string>

Option containing the hex color if valid

Example

isHexColor('#ff0000')
// => Some('#ff0000')

isHexColor('fff')
// => Some('fff')

isHexColor('#ff00ff80')
// => Some('#ff00ff80') (with alpha)

isHexColor('not-a-color')
// => None