PHPackages                             hampel/validate - 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. hampel/validate

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

hampel/validate
===============

Simple validator library composer package

2.2.3(6y ago)05.3k↓33.3%2MITPHPPHP &gt;=7.2.0

Since Jul 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hampel/validate)[ Packagist](https://packagist.org/packages/hampel/validate)[ Docs](https://bitbucket.org/hampel/validate)[ RSS](/packages/hampel-validate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (18)Used By (2)

Hampel Validator
================

[](#hampel-validator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/97b998f336d41ccac0a8e7a2744914015cb678a7c80c00d909f09d6b0a5c278b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616d70656c2f76616c69646174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/validate)[![Total Downloads](https://camo.githubusercontent.com/a1c9dd541ec5d6bb791534cb4df0a41424941b20b9a174b1e74fd0cbb6e61838/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616d70656c2f76616c69646174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/validate)[![Open Issues](https://camo.githubusercontent.com/bc9a552f65d740edda245ab6ee72cb45787d2f52e6d51750d27e7491fadbc3b1/68747470733a2f2f696d672e736869656c64732e696f2f6269746275636b65742f6973737565732f68616d70656c2f76616c69646174652e7376673f7374796c653d666c61742d737175617265)](https://bitbucket.org/hampel/validate/issues)[![License](https://camo.githubusercontent.com/417fcd2a2a389ae1b3f0f9b14a73e0f663ac9053517acf352543bbb8e26c9b2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616d70656c2f76616c69646174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/validate)

Simple validator library composer package

By [Simon Hampel](mailto:simon@hampelgroup.com)

Installation
------------

[](#installation)

The recommended way of installing Hampel Validator is through [Composer](http://getcomposer.org):

Require the package via Composer in your `composer.json`

```
:::json
{
    "require": {
        "hampel/validate": "^2.2"
    }
}

```

Run Composer to update the new requirement.

```
:::bash
$ composer update

```

Notes
-----

[](#notes)

Version 2.2 of this library removes the Validator::getTlds() method and the ManageTlds class. We leave it up to the implementer to source their own list of valid TLDs.

If using Laravel, we recommend installing the "hampel/tlds" package which uses this package and also supplies a simple mechanism for retrieving (and optionally caching) the TLD list directly from IANA or other sources. The TLDs package also extends the Laravel validation service with additional rules for validating domain names and TLDs.

Again, if using Laravel, we also recommend installing the "hampel/validate-laravel" package which extends the Laravel validation service with additional rules based on the validation rules in this package (excluding the TLD validation provided by "hampel/tlds".

Usage
-----

[](#usage)

*Example*:

```
:::php
$value = "1";
$validator = new Validator;
dd($validator->isBool($value));

```

**isEmail** returns true for validly formed email addresses

**isBool** returns true for "1", "true", "on" and "yes", "0", "false", "off", "no", and "", and NULL ... and returns false for any other value

```
:::php
// the following all evaluate to boolean true
$validator->isBool(true);
$validator->isBool(1);
$validator->isBool("on");
$validator->isBool("yes");
$validator->isBool(false);
$validator->isBool(0);
$validator->isBool("off");
$validator->isBool("no");
$validator->isBool("");
$validator->isBool(null);

// the following will evaluate to boolean false (ie not valid boolean values)
$validator->isBool("foo"));
$validator->isBool(2);

```

**isIpv4** returns true for any valid IPv4 address, including private and reserved addresses

```
:::php
 // the following all evaluate to true
$validator->isIpv4("0.0.0.0");
$validator->isIpv4("1.1.1.1");
$validator->isIpv4("10.0.0.1");
$validator->isIpv4("192.168.0.1");
$validator->isIpv4("255.255.255.255");

```

**isPublicIpv4** returns true for valid IPv4 addresses which are not in the private or reserved ranges

```
:::php
// the following evaluate to true
$validator->isPublicIpv4("1.1.1.1");
$validator->isPublicIpv4("74.125.237.2");

// the following evaluate to false
$validator->isPublicIpv4("0.0.0.0");
$validator->isPublicIpv4("10.0.0.1");
$validator->isPublicIpv4("192.168.0.1");

```

**isIpv6** returns true for any valid IPv6 address, including private and reserved addresses

**isPublicIpv6** returns true for valid IPv6 addresses which are not considered non-routable

**isIp** returns true for any valid IPv4 or IPv6 address

**isPublicIP** returns true for any public IPv4 or IPv6 address

**isDomain** returns true for any validly constructed domain name, including internationalisation in punycode notation

```
:::php
// the following evaluate to true
$validator->isDomain("example.com");
$validator->isDomain("www.example.com.au");
$validator->isDomain("www-2.example.com");
$validator->isDomain("example.foo"); // valid because we don't perform strict checking of TLDs

// the following evaluate to false
$validator->isDomain("example_1.com"); // underscores not allowed
$validator->isDomain("example."); // no TLD
$validator->isDomain("example"); // no TLD

// Supply an array of TLDs to validate against for more strict validation
$tlds = array('com', 'au', 'travel', 'xn--3e0b707e');

$validator->isDomain('example.com', $tlds)); // true
$validator->isDomain('example.foo', $tlds)); // false

```

**isTld** returns true for any valid TLD when compared to the list of TLDs passed to the function in an array

You may pass a full domain and `isTld` will check that the TLD extension is valid (but will not validate the domain itself)

```
:::php
// Supply an array of TLDs to validate against for more strict validation
$tlds = array('com', 'au', 'travel', 'xn--3e0b707e');

$validator->isTld('com', $tlds)); // true
$validator->isTld('.com', $tlds)); // true
$validator->isTld('example.com', $tlds)); // true
$validator->isTld('---.com', $tlds)); // true, since we don't validate the domain itself

$validator->isDomain('---.com', $tlds)); // false, validates both domain and TLD
$validator->isDomain('foo', $tlds)); // false
$validator->isDomain('example.foo', $tlds)); // false

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~141 days

Recently: every ~458 days

Total

17

Last Release

2415d ago

Major Versions

0.1.0 → 1.0.02013-08-28

1.1.0 → 2.0.02013-10-11

PHP version history (2 changes)0.1.0PHP &gt;=5.3.0

2.2.3PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2e02745af0cfa73e5f00eb8faf965a13296351e62f4802cc76a148cdbc95dbd?d=identicon)[hampel](/maintainers/hampel)

---

Top Contributors

[![simonhampel](https://avatars.githubusercontent.com/u/443890?v=4)](https://github.com/simonhampel "simonhampel (49 commits)")

---

Tags

validation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hampel-validate/health.svg)

```
[![Health](https://phpackages.com/badges/hampel-validate/health.svg)](https://phpackages.com/packages/hampel-validate)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M672](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8912.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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