定制 hampel/validate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hampel/validate

最新稳定版本:2.2.3

Composer 安装命令:

composer require hampel/validate

包简介

Simple validator library composer package

关键字:

README 文档

README

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

统计信息

  • 总下载量: 5.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-07-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固