if ($this->request->isPost()) {
$validate = new Validate([
'bar_name' => 'require',
'bar_phone' => 'require|regex:1[3-8]{1}[0-9]{9}',
'business_hours' => 'require',
'user_nickname' => 'chsDash|max:32',
'sex' => 'number|between:0,2',
'birthday' => 'dateFormat:Y-m-d|after:-88 year|before:-1 day',
'user_url' => 'url|max:64',
'signature' => 'chsDash|max:128',
]);
$validate->message([
'bar_name.require' => '酒吧名称不能为空',
'bar_phone.require' => '手机号不能为空',
'bar_phone.regex' => '必须为手机号',
'user_nickname.chsDash' => '昵称只能是汉字、字母、数字和下划线_及破折号-',
'user_nickname.max' => '昵称最大长度为32个字符',
'sex.number' => '请选择性别',
'sex.between' => '无效的性别选项',
'birthday.dateFormat' => '生日格式不正确',
'birthday.after' => '出生日期也太早了吧?',
'birthday.before' => '出生日期也太晚了吧?',
'user_url.url' => '个人网址错误',
'user_url.max' => '个人网址长度不得超过64个字符',
'signature.chsDash' => '个性签名只能是汉字、字母、数字和下划线_及破折号-',
'signature.max' => '个性签名长度不得超过128个字符',
]);
$data = $this->request->post();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$editData = new UserModel();
if ($editData->editData($data)) {
$this->success("保存成功!", "user/profile/center");
} else {
$this->error("没有新的修改信息!");
}
}
thinkphp5 验证规则 实例化Validate
最新推荐文章于 2021-05-07 11:12:54 发布