Live demo
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
| Name | Description | Type | Default |
|---|---|---|---|
signature | Static — drop into a validators array. | ValidatorFn | — |
accepted shapes | #abc, #abcd, #a1b2c3, #a1b2c3d4 (case-insensitive). Hash required. | string | — |
error key | On failure: { hexColor: true }. Empty value passes. | { hexColor: true } | — |