cakephp/validation

CakePHP 验证库

5.1.0 2024-09-06 12:23 UTC

This package is auto-updated.

Last update: 2024-09-21 03:08:16 UTC


README

Total Downloads License

CakePHP 验证库

CakePHP 验证库提供构建验证器的功能,可以轻松地验证任意数组的数据。

用法

验证器对象定义了一组字段所应用的规则。验证器对象包含字段与验证集之间的映射。创建验证器很简单

use Cake\Validation\Validator;

$validator = new Validator();
$validator
    ->requirePresence('email')
    ->add('email', 'validFormat', [
        'rule' => 'email',
        'message' => 'E-mail must be valid'
    ])
    ->requirePresence('name')
    ->notEmptyString('name', 'We need your name.')
    ->requirePresence('comment')
    ->notEmptyString('comment', 'You need to give a comment.');

$errors = $validator->validate($_POST);
if (!empty($errors)) {
    // display errors.
}

文档

请确保您查阅了官方文档