import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';
@Component({ imports: [WrInput] })
export class MyComponent {}url
Check a URL, and optionally its scheme.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Live demo — any scheme
Live demo — HTTPS only
Usage
A scheme is required. url({ requireProtocol: false }) also accepts ngwr.dev.
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'] } }API
| Name | Description | Type | Default |
|---|---|---|---|
signature | Call it to get a ValidatorFn. | (options?: { protocols?: readonly string[]; requireProtocol?: boolean }) => ValidatorFn | — |
options.protocols | Accepted schemes, any case, with or without :. | readonly string[] | any scheme |
options.requireProtocol | When false, ngwr.dev passes, read as https://ngwr.dev. | boolean | true |
error key | Not a URL: { url: true }. Wrong scheme: { url: { allowed: [...] } }. Empty value passes. | { url: true | { allowed: string[] } } | — |