# url

> Parse with `new URL()` and optionally restrict by scheme. Empty values pass.

Source: https://ngwr.dev/reference/validators/url  
Kind: Validator

## Live demo — any scheme

## Live demo — HTTPS only

## Usage

```angular-ts
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[] } }` | `—` |

## See also

- [wr-input](https://ngwr.dev/reference/components/input) — Host control for link entry.
- [wr-form-field](https://ngwr.dev/reference/components/form-field) — Label / hint / error scaffolding around it.
