批改状态:未批改
老师批语:
<?php
namespace app\validate;
use think\Validate;
class User extends Validate{
// 验证规则
protected $rule = [
'name' => 'require|min:5|max:15',
'email' => 'require|email|length:5,40',
'password' => 'require|length:6,50',
];
// 自定义错误信息
protected $message = [
'name.require' => '姓名不能为空',
'name.min' => '姓名不能少于5字符',
'name.max' => '姓名不能大于15个字符',
'email.require' => 'Email不能为空',
'email.email' => 'Email格式不正确',
'email.length' => 'Email长度在5-40字符之间',
'password.require' => '密码不能为空',
'password.length' => '密码长度在20-50之间',
];
}点击 "运行实例" 按钮查看在线实例
<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use app\validate\User;
class Verify extends Controller
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index(User $user)
{
$data = ['name' => 'gakkispy', 'email' => 'mail@php.cn', 'password' => 'password'];
$res= $user->check($data);
return $res ? 'success' : $user->getError();
}
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号