批改状态:合格
老师批语:
5月25日作业
验证器:www.tp51.io/index.php/test/docfy/test1
<?php
namespace app\test\controller;
//window 窗口: 自动创建test/model/Docfy.php
//方法:D:\PHPTOOL\myphp_www\PHPTutorial\WWW\www.51.io>php think make: controller test/Docfy
use think\Controller;
use app\validate\Docv;
use think\validate;
class Docfy extends Controller
{
//验证器: 直接实例化验证器完成验证
public function test1()
{
//准备要验证的数据
$data = [
'title' => 'zouhaifu',
'type' => 'ppt',
'con' => 'zouhaifu',
'state' => 1,
'email' => '123@qq.com',
'mobile' => 13809444666,
'id_card'=>'980104195904010012'
];
$validate = new Docv();
if(!$validate -> check($data)){
dump($validate -> getError());
}else{
return '通过验证';
}
}
}点击 "运行实例" 按钮查看在线实例
验证规则及错误信息:application/validate/docv.php
<?php
namespace app\validate;
use think\Validate;
class Docv extends Validate
{
//创建验证规则
//以属性的方式进行配置,属性不能更改
protected $rule = [
'title'=>'require|min:6|max:45',
'type' => 'require|ppt',
'con'=> 'require|min:6|max:620',
'state' => 'in: 0,1',
'email' => 'require|email',
'mobile' => 'require|mobile',
'id_card'=> 'require|idCard'
];
//错误信息可以自定义:
protected $message = [
'title.require' => '文章标题不能为空',
'title.min' => '文章标题不能少于6个字符',
'title.max' => '文章标题不能大于45个字符',
'type.require' => '文章格式不能为空',
'con.requrire' => '文章内容不能为空',
'con.min' => '文章内容不能少于6个字符',
'con.max' => '文章内容不能大于45个字符',
'state.in' => '状态只能选择‘使用’或‘过期’',
'email.require' => '邮箱不能为空',
'email.email' => '邮箱格式不对',
'mobile.require' => '手机不能为空',
'mobile.mobile' => '手机格式不对',
'id_card.require' => '身份证不能为空',
'id_card.idCard' => '身份证格式不对date/'
];
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号