Skip to main content

PHP常用正则表达式,自己项目中使用,收集中。

//判断手机号

if(preg_match(“/^1[3458]{1}\d{9}$/”,$phonenumber)){
echo “是手机号码”;
}else{
echo “不是手机号码”;
}

//判断邮箱

function CheckEmail($email)
{
global $dArr;
$dArr = array(
'163.com','126.com','sina.com','yahoo.com.cn','yahoo.com','sohu.com','yeah.net','139.com',
'tom.com','21cn.com','qq.com','foxmail.com','gmail.com','hotmail.com','263.net',
'vip.qq.com','vip.163.com','vip.sina.com','vip.sina.com.cn','vip.foxmail.com',
);
if(empty($email)) return FALSE;
list($e,$d) = explode('@', $email);
if(!empty($e) && !empty($d))
{
$d = strtolower($d);
if(!in_array($d,$dArr)) return FALSE;
return preg_match('/^[a-z0-9]+([\+_\-\.]?[a-z0-9]+)*/i', $e);
}
return FALSE;
}