Toolbox-XToolbox-X

Static Validation Checks

Validate CSS named colors and hex, RGB, and HSL formats using the Color class.

Color Format Checkers

Note

Please refer to the color types here: Color Types to understand the color types used in the examples below.

For individual checker functions, consider using the standalone Checker Functions.

isHex6()

Validates if a string is a valid 6-character hex color.

Signature

static isHex6(color: string): color is Hex6

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if valid Hex6.

Example

playground.ts

isHex8()

Validates if a string is a valid 8-character hex color (with alpha channel).

Signature

static isHex8(color: string): color is Hex8

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if valid Hex8.

Example

playground.ts

isRGB()

Validates if a string matches the standard solid rgb() color format.

Signature

static isRGB(color: string): color is RGB

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if valid RGB.

Example

playground.ts

isRGBA()

Validates if a string matches the alpha rgba() color format.

Signature

static isRGBA(color: string): color is RGBA

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if valid RGBA.

Example

playground.ts

isHSL()

Validates if a string matches the standard solid hsl() color format.

Signature

static isHSL(color: string): color is HSL

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if valid HSL.

Example

playground.ts

isHSLA()

Validates if a string matches the alpha hsla() color format.

Signature

static isHSLA(color: string): color is HSLA

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if valid HSLA.

Example

playground.ts

Validation Rules

Hex Formats

  • Hex6: Exactly 6 hexadecimal characters after #.
  • Hex8: Exactly 8 hexadecimal characters after # (includes alpha).

RGB/RGBA Formats

  • Red, Green, Blue: Must be between 0-255 (inclusive).
  • Alpha: Must be between 0-1 (inclusive).

HSL/HSLA Formats

  • Hue: Must be between 0-360 (inclusive).
  • Saturation: Must be between 0-100% (inclusive).
  • Lightness: Must be between 0-100% (inclusive).
  • Alpha: Must be between 0-1 (inclusive).

isCSSColor()

Validates if a string is a valid CSS named color.

Signature

static isCSSColor(color: string): color is CSSColor

Parameters

ParameterTypeDescription
colorstringThe string to validate.

Returns

  • boolean: true if a valid CSS color name.

Example

playground.ts

Last updated: Mon, Jun 15, 2026 09:49:35PM (UTC)

On this page