正则案例

来源:互联网 发布:ubuntu系统软件位置 编辑:程序博客网 时间:2024/05/22 12:57
        //website判定        $website = strtolower(trim($_POST['website']));        if (!preg_match('/^(http)(s)?(:\/\/)([\w\d-]+\.)+[\w-]+(\/[\d\w-.\/?%&=]*)?$/',$website)){            $json->setErr('10008','网址格式错误');            $json->Send();        }        //邮箱验证        $email = trim($_POST['email']);        if (!preg_match('/[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*/',$email)){            $json->setErr('10009','邮箱格式错误');            $json->Send();        }        //联系方式验证;        $tel = trim($_POST['telphone']);        if (!preg_match('/^(1(([35][0-9])|(47)|[8][0-9]|[7][0-9]))\d{8}$/',$tel) && !preg_match('/^0[0-9]{2,3}[-]?\d{7,8}$/',$tel)){            $json->setErr('10010','联系方式格式错误');            $json->Send();        }

原创粉丝点击