think php5 自定义手机号正则的验证
2019-01-16 本文已影响7人
CoderZb
think php5中有些正则不存在,例如手机号正则,此时我们可以自定义。代码如下:
<?php
namespace app\master\validate;
use think\Validate;
class VentureloanValidate extends Validate
{
protected $rule = [
'fdrsj' => 'require|regex:1[3-8]{1}[0-9]{9}',
'fdryx' => 'require|email',
// gjyjzybhpz 国家一级中药保护品种
'gjyjzybhpz' => 'require',
];
protected $message = [
'fdrsj.require' => '法定代表人手机不能为空',
'fdrsj.regex' => '手机号格式不正确',
'fdryx.require' => '法定代表人邮箱不能为空',
'fdryx.email' => '邮箱格式不正确',
'gjyjzybhpz.require' => '国家一级中药保护品种不能为空',
];
}
手机号输入错误,内容如下

弹框如下
