Validator

hexColor

3, 4, 6, or 8-digit hex colour with a leading #. Case-insensitive. Empty values pass.

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 }

Why ngwr provides this

No built-in validates colour strings. This accepts the 3/4/6/8-digit hex forms (#abc, #1a2b3c4d) — handy for free-text colour fields next to wr-color-picker.

API

NameDescriptionTypeDefault
signatureStatic — drop into a validators array.ValidatorFn
accepted shapes#abc, #abcd, #a1b2c3, #a1b2c3d4 (case-insensitive). Hash required.string
error keyOn failure: { hexColor: true }. Empty value passes.{ hexColor: true }

See also