美文网首页
think php5 自定义手机号正则的验证

think php5 自定义手机号正则的验证

作者: CoderZb | 来源:发表于2019-01-16 18:51 被阅读7次

    ThinkPHP5.0完全开发手册
    ThinkPHP验证规则篇

    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' => '国家一级中药保护品种不能为空',
    
                ];
    }
    

    手机号输入错误,内容如下

    image.png

    弹框如下

    image.png

    相关文章

      网友评论

          本文标题:think php5 自定义手机号正则的验证

          本文链接:https://www.haomeiwen.com/subject/ccoxrqtx.html