ValidatorOptional

hexColor

Check a hex colour such as #abc or #1a2b3c.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';

@Component({ imports: [WrInput] })
export class MyComponent {}

Live demo

errors: null

Usage

import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';

const colour = new FormControl('', [WrValidators.hexColor]);

colour.setValue('#1a2b3c');  // valid
colour.setValue('#xyz');     // { hexColor: true }

API

NameDescriptionTypeDefault
signatureAdd it to a validators array.ValidatorFn—
accepted shapes#abc, #abcd, #a1b2c3, #a1b2c3d4, any case. The # is required.string—
error keyOn failure: { hexColor: true }. Empty value passes.{ hexColor: true }—

See also