raoul/php-validator
最新稳定版本:V1.1.0
Composer 安装命令:
composer require raoul/php-validator
包简介
A simple validator for PHP
关键字:
README 文档
README
How to install
composer require raoul/php-validator
Or
git clone https://github.com/RaoulvanWijk/Validator.git
How to use it?
To use my validator you can either instantiate the validator class
require_once __DIR__ .'/vendor/autoload.php'; use Raoul\Validator\Validator; $validator = new Validator();
or create a new class that extends the base validator class
require_once __DIR__ .'/vendor/autoload.php'; use Raoul\Validator\Validator; Class CustomValidator extends Validator { public function rules() { return [ // Your rules go here ]; } public function messages() { return [ // Your custom messages go here ]; } } $validator = new CustomValidator();
And then call the validate method with the needed data
$validator->validate($data);
Specifying the rules
You have 2 options when specifying the rules when calling the validate method
$validator->validate($data, [ 'name' => ['required', 'min:4'], 'email' => 'required|email' ]);
or in the rules() method
public function rules() { return [ 'name' => ['required', 'min:4'], 'email' => 'required|email' ]; }
Specifying custom validation messages
available validation rules
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-25