url
Validate that a string is a syntactically valid URL.
Signature
NguardValidators.String.url: ValidatorFn
A parameterless validator — used directly without invocation.
Reactive forms
import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';
const homepage = new FormControl('', [NguardValidators.String.url]);
Template-driven forms
<input ngModel name="homepage" type="url" nguardUrl />
Error key
{ url: true }
Notes
- Accepts the common shapes:
http://www.example.comhttps://www.example.comwww.example.comexample.com
- Query strings and complex paths are accepted.
- Validates syntax, not reachability — use an Async validator for live checks.
- A protocol-less URL (
example.com) passes. If you require a scheme, combine withregex(/^https?:\/\//).