PHP笔记网

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2020-09-11 16:26:55  修改时间:2024-12-15 05:40:54  分类:12.PHP库/系统/微信  编辑

CI验证器

示例1:

$post = [
    'username' => '',
    'password' => '',
    'passconf' => '',
    'email'    => '',
];

// 验证表单
$validator = new FormValidator($post);

$validator->setRules('username', '用户名', 'required', ['required' => '“用户名”不能为空']);
$validator->setRules('password', '密码', 'required');
$validator->setRules('passconf', '确认密码', 'required');
$validator->setRules('email', '邮箱', 'required');

$ret = $validator->run();
if ($ret == false) {
    echo '表单验证失败:' . $validator->errorFirst();
}