Back to Validation

Url

docs/validators/Url.md

3.1.12.3 KB
Original Source
<!-- SPDX-License-Identifier: MIT SPDX-FileCopyrightText: (c) Respect Project Contributors SPDX-FileContributor: Alexandre Gomes Gaigalas <[email protected]> SPDX-FileContributor: Henrique Moody <[email protected]> -->

Url

  • Url()

Validates whether the input is a valid URL in a popular internet format.

php
v::url()->assert('http://example.com');
// Validation passes successfully

v::url()->assert('https://www.youtube.com/watch?v=6FOUqQt3Kg0');
// Validation passes successfully

v::url()->assert('ldap://[::1]');
// Validation passes successfully

v::url()->assert('mailto:[email protected]');
// Validation passes successfully

v::url()->assert('http://example.this_top_level_domain_does_not_exist');
// → "http://example.this_top_level_domain_does_not_exist" must be a URL

This validator uses [Ip][Ip.md], [Domain][Domain.md] and [Email][Email.md] internally, activating them depending on the input scheme.

If you want to restrict URLs to a specific scheme, you can use [StartsWith][StartsWith.md] or any other verifier:

php
v::startsWith('http')->url()->assert('http://example.com');
// Validation passes successfully

v::startsWith('http')->url()->assert('ftp://example.com');
// → "ftp://example.com" must start with "http"

Templates

Url::TEMPLATE_STANDARD

ModeTemplate
default{{subject}} must be a URL
inverted{{subject}} must not be a URL

Template placeholders

PlaceholderDescription
subjectThe validated input or the custom validator name (if specified).

Categorization

  • Internet

Changelog

VersionDescription
3.0.0Templates changed
3.0.0Stricter use of Ip, Domain and Email internally. Select schemes only.
0.8.0Created

See Also