Download the PHP package hampel/validate without Composer

On this page you can find all versions of the php package hampel/validate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validate

Hampel Validator

Latest Version on Packagist Total Downloads Open Issues License

Simple validator library composer package

By Simon Hampel

Installation

The recommended way of installing Hampel Validator is through Composer:

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

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

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

All versions of validate with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hampel/validate contains the following files

Loading the files please wait ....