匹配域名:(这个还不是很好,有空查看一下以前孙凯写的)
$urlRule = "/(http|https)://[0-9a-z/-]+[0-9a-z./-?=]+[0-9a-z./-=&]*/";
if (!preg_match($urlRule, $data['appurl'])) {
$this->error('app登录成功后打开的地址格式错误!');die;
}
匹配邮箱:
$emailRule = "/^w+(.w+)*@w+(.w+)+$/";
匹配手机号:
$phoneRule = "/^1[3458]d{9}$|17[8673]/d{8}$/";
if (!preg_match($phoneRule, $data['phone'])) {
echo "<script type='text/javascript'>alert('手机号格式错误');history.back();</script>";exit;
}
匹配日期:
$dataRule = "/(d{4}-((0?[1-9])|(1[0-2]))-((0?[1-9])|([1-2][0-9])|(3[01]))s+((0?[1-9])|(1[0-9])|(2[0-4])):[0-5]+[0-9](:[0-5]+[0-9])+)/";
$dateRule2 = "/(d{4}(-|年)((0?[1-9])|(1[0-2]))(-|月)((0?[1-9])|([1-2][0-9])|(3[01]))(日)?s+((0?[1-9])|(1[0-9])|(2[0-4])):[0-5]+[0-9](:[0-5]+[0-9])+)/";
匹配用户名:
$ruler1="/^[x{4e00}-x{9fa5}A-Za-z0-9_]{4,12}+$/u";
if(!preg_match($ruler1, $username)){
echo "<script>alert('用户名格式错误')</script>";
echo "<script type='text/javascript'>history.back();</script>";
exit;
}
匹配密码:
$pwdRule = "/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/";(西湖的)
$pwdRule2 = "/^[x{4e00}-x{9fa5}A-Za-z0-9_]{6,12}+$/u";(我的)
if (!preg_match($pwdRule , $data['pwd'])) {
echo "<script type='text/javascript'>alert('密码必须由6-20位字母、数字组合');history.back();</script>";
}
//记得判断数据是否完整
if(empty($username) || empty($password) || empty($status) || empty($phone)){
echo "<script>alert('数据不完整')</script>";
echo "<script type='text/javascript'>history.back();</script>";
exit;
}