Live demo — any scheme
Live demo — HTTPS only
Usage
import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';
const link = new FormControl('', [WrValidators.url()]);
const secure = new FormControl('', [
WrValidators.url({ protocols: ['https'] }),
]);
secure.setValue('http://example.com');
secure.errors; // { url: { allowed: ['https'] } }Why ngwr provides this
Hand-rolled URL regexes via Validators.pattern are notoriously wrong. This defers to the platform URL parser and can restrict protocols. A scheme is required by default; pass url({ requireProtocol: false }) to also accept bare domains like ngwr.dev (assuming https).
API
| Name | Description | Type | Default |
|---|---|---|---|
signature | Factory — call it to get a ValidatorFn. | (opts?) => ValidatorFn | — |
options.protocols | Whitelist of accepted schemes. Trailing : optional. Case-insensitive. | readonly string[] | any scheme |
options.requireProtocol | When false, bare domains like ngwr.dev are accepted (parsed as if prefixed with https://). | boolean | true |
error key | On unparseable input: { url: true }. On scheme mismatch: { url: { allowed: [...] } }. Empty value passes. | { url: true | { allowed: string[] } } | — |