29 lines
703 B
PHP
29 lines
703 B
PHP
<?php
|
|
namespace app\validate;
|
|
|
|
use think\Validate;
|
|
|
|
class Message extends Validate
|
|
{
|
|
protected $rule = [
|
|
'username|联系人' => 'require|length:1,64',
|
|
'tel|联系电话' => 'require|checkTel',
|
|
'email|邮箱' => 'email',
|
|
'content|留言内容' => 'length:1,120'
|
|
];
|
|
protected $message = [
|
|
'username.require' => '联系人不能为空',
|
|
'tel' => '联系方式错误',
|
|
'content.require' => '问题描述不能为空',
|
|
|
|
];
|
|
// 自定义验证规则
|
|
protected function checkTel($value, $rule, $data=[])
|
|
{
|
|
if(preg_match("/^1[345789]\d{9}$/", $value)){
|
|
return true ;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} |