凌的博客

您现在的位置是: 首页 > 学无止境 > PHP > 

PHP

php 验证手机号、邮箱

2019-08-23 PHP 1086

常用的正则验证规则

if (isset($post['email'])) {
    if (!preg_match("/^\w+\.?\w*@\w+\.\w*\.?[a-z]{2,}$/", $post['email'])) {
        $this->error('邮箱格式不对');
    }
    $data['email'] = $post['email'];
}


if (isset($post['mobile'])) {
    if (!preg_match("/1\d{10}/", $post['mobile'])) {
        $this->error('手机号格式不对');
    }
    $data['mobile'] = $post['mobile'];
}


文章评论

0条评论