mohammedalkutrani / validator
验证表单数据
v1.0.1
2020-01-28 22:05 UTC
Requires (Dev)
- phpunit/phpunit: ^8
- webmozart/assert: 1.6.0
This package is auto-updated.
Last update: 2024-09-05 17:37:27 UTC
README
这是一个在触及数据库之前验证数据的简单包。
核心功能
- PSR-4 用于自动加载。
- PSR-2 用于编码风格。
- 策略模式,用于在运行时更改规则。
- 外观模式,使其易于使用。
- 实现您自己的规则。
- 100% 测试。
安装
composer require mohammedalkutrani/validator
简单用法
use Validator\Facade\Validation; use Validator\Rules; $v = Validation::make( [ // the given data. 'name' => 'mohammedalkutrani@gmail.com', 'age' => 25 ], [ // the rules for the data. 'name' => [Rules::NUMBER, Rules::MIN.'|4'], 'age' => [Rules::EMAIL] ] ); // check if it passed if(!$v->isPassed()) // it will return boolean { print_r($v->getMessages()); // getting the messages. }
结果
Array ( [name] => Array ( [0] => the name should be a number [1] => the name should shorter then 4 ) [age] => Array ( [0] => the age should be an email ) )