amitkhare/validbit

此包已被弃用且不再维护。作者建议使用 amitkhare/easy-validation 包代替。

ValidBit 是一个简单易用的 PHP 验证库

0.2.5 2016-05-08 13:52 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:58:09 UTC


README

Validbit 是一个易于使用的 PHP 验证库

此包已被弃用且不再维护。请使用 https://github.com/amitkhare/easy-validation 包代替。

安装

从您想安装的目录运行此命令。

通过 Composer

php composer.phar require amitkhare/validbit

通过 Git

git clone https://github.com/amitkhare/validbit.git

手动安装

Download: https://github.com/amitkhare/validbit/archive/master.zip
Extract it, require "PATH-TO/"."validbit.php" where you want to use it.

使用方法

<?php
use AmitKhare\ValidBit; // use namespace.

require("PATH-TO/"."validbit.php"); // only need to include if installed manually.

$v = new ValidBit(); // instantiate ValidBit;

//  OR with database for unique field check
$v = new ValidBit($host,$username,$password,$dbname); // instantiate ValidBit With Database features;

$v->setSource($_POST); // set data source array;

$v->check("mobile","required|numeric|min:10|max:15");
$v->check("username","required|alphanum|unique:users.username|min:4|max:20");
$v->check("email","required|email|unique:users.email|min:4|max:100");

$v->match("password","password_confirm","required|min:6|max:25");

if(!$v->isValid()){
    print_r($v->getStatus());
}

可用方法

> $v->check("FIELD","RULES");
> $v->match("FIELD1","FIELD2","RULES");

可用规则

> required
> email
> url
> numeric
> string
> float
> ipv4
> ipv6
> bool
> min
> max
> alphanum
> alphanumUnicode
> unique (avaiable only if instantiate ValidBit With Database);