首页 > 移动平台 > 详细

正则表达式验证手机和邮箱格式

时间:2020-10-29 19:53:51      阅读:29      评论:0      收藏:0      [点我收藏+]
if (!function_exists("check_mobile")) {
/**
* 检验手机号格式
* @param $phone 手机号
* @param int $countryCode 区号
* @return bool
* User: 陈启泽
* DateTime: 2020/9/22 14:35
*/
function check_mobile($phone,$countryCode=86)
{
$phone = trim($phone);
if (empty($countryCode)) {
$countryCode = 86;
}
if ($countryCode == 86 ) {
$chars = "/^1[3-9]{1}[0-9]{1}[0-9]{8}$/";
if (preg_match($chars, $phone)) {
return true;
}
}else if ($countryCode == 852) {
if (preg_match(‘/^[0-9]{8}$/‘, $phone)) {
return true;
}
}else if ($countryCode == 60) {
if (preg_match(‘/^0?1(1\d{8}|[02-9]\d{7})$/‘, $phone)) {
return true;
}
}else {
if (preg_match(‘/^[0-9]*$/‘, $phone)) {
return true;
}
}


return false;
}
}

if (!function_exists("check_email")) {
/**
* 检验邮箱格式
* @param string $email 邮箱
* @return boolean bool true格式正确,false格式错误
* User: 陈启泽
* DateTime: 2020/9/22 14:44
*/
function check_email($email){
$email = trim($email);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return true;
}else{
return false;
}
}
}

正则表达式验证手机和邮箱格式

原文:https://www.cnblogs.com/qize/p/13897773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!