Is Hexadecimal Colour
Added in: @sardine/colour@1.2.0
Description
Checks if a given string is a valid hexadecimal colour format.
Signature
function isHexColour(hex: string): boolean;
Parameters
hex
:string
— The string to validate (e.g.,"#ffe000"
).
Returns
boolean
—true
if the string is a valid hexadecimal colour, otherwisefalse
.
Examples
import { isHexColour } from "@sardine/colour";
isHexColour("#ffe000");
// => true
isHexColour("#xyz123");
// => false
Error Handling
- Returns
false
for invalid input; does not throw errors.
Interactive Demo
Try the function yourself with our interactive playground: