PHPackages                             fleshgrinder/url-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. fleshgrinder/url-validator

AbandonedArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

fleshgrinder/url-validator
==========================

A regular expression to validate URLs.

1129.8k7[1 issues](https://github.com/Fleshgrinder/php-url-validator/issues)PHP

Since Mar 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Fleshgrinder/php-url-validator)[ Packagist](https://packagist.org/packages/fleshgrinder/url-validator)[ RSS](/packages/fleshgrinder-url-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

URL Validation
==============

[](#url-validation)

I made this repository specifically for Mathias Bynens' little “\[in search of the perfect URL validation regex\] ([https://mathiasbynens.be/demo/url-regex)”](https://mathiasbynens.be/demo/url-regex)%E2%80%9D) challenge and if I may spoiler you from the beginning, mine is not perfect. But it is a step closer to it.

The regular expression contains parts from \[Diego Perini's regular expression and the comments on his Gist\] () as well as some stuff from the \[Symfony URL constraint pattern\] ().

Note that the challenge does not cover all possible valid URL constructs. The unit test contains several URLs which should be valid and not valid which are not part of the challenge.

Also note that this class is not meant as a real validator, it is more a starting point for a validator. I had to release the code under the MIT license because it incorporates a big portion of Diego Perini's regular expression—but I will ask him if it is possible for me to release it under the [Unlicense](http://unlicense.org) license. If you plan to use this regular expression in your code consider to remove the username, password, port and IP address support; since such addresses should not be used for e.g. homepages of users on a profile page or within comments on a blog post.

On a last note, the class also contains a scheme (aka protocol) validation regular expression.

The provided unit test has a 100% coverage of the little class and the code is PHP 5.3+ compatible.

Features
--------

[](#features)

- Full [Internationalized Domain Name (IDN)](https://en.wikipedia.org/wiki/Internationalized_domain_name) support.
- Full support for [Punycode](https://en.wikipedia.org/wiki/Punycode).
- Support for IPv4 and IPv6 addresses as hostname.
- Extraction of URL parts (like [`parse_url`](https://php.net/parse-url)):
    - Scheme (aka protocol)
    - Username
    - Password
    - Hostname
        - Domain + TLD
        - IPv4
        - IPv6
    - Port
    - Path
    - Query
    - Fragment

Install
-------

[](#install)

The class and tests are available via [composer](https://getcomposer.org/).

```
composer require fleshgrinder/url-validator dev-master
```

TODO
----

[](#todo)

- IPv6 address validation totally relies on [PHP's `filter_var`](https://php.net/filter-var) implementation, find a way to validate it with the regular expression.
- Port the regular expression to JavaScript for usage in HTML input URL elements and of course JavaScript itself.
- Find more funny URLs for the unit test.

Weblinks
--------

[](#weblinks)

- [Packagist](https://packagist.org/packages/fleshgrinder/url-validator)

License
-------

[](#license)

> The MIT License (MIT)
>
> For more information, please refer to [https://en.wikipedia.org/wiki/MIT\_License](https://en.wikipedia.org/wiki/MIT_License)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6680298143064cd3ac63c0097ef724d46f47221ae0990db445081c4e8a923e05?d=identicon)[Fleshgrinder](/maintainers/Fleshgrinder)

---

Top Contributors

[![Fleshgrinder](https://avatars.githubusercontent.com/u/1059453?v=4)](https://github.com/Fleshgrinder "Fleshgrinder (7 commits)")[![aripringle](https://avatars.githubusercontent.com/u/1278449?v=4)](https://github.com/aripringle "aripringle (1 commits)")[![jaydiablo](https://avatars.githubusercontent.com/u/136907?v=4)](https://github.com/jaydiablo "jaydiablo (1 commits)")

### Embed Badge

![Health badge](/badges/fleshgrinder-url-validator/health.svg)

```
[![Health](https://phpackages.com/badges/fleshgrinder-url-validator/health.svg)](https://phpackages.com/packages/fleshgrinder-url-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
