php验证手机号码和邮箱

yellowone

关注

阅读 107

2022-06-06

/**
* 验证手机号是否正确
* @author honfei
* @param number $mobile
*/
function isMobile($mobile) {
if (!is_numeric($mobile)) {
return false;
}
return preg_match('#^1[3,4,5,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false;
}


/**
* 正则表达式验证email格式
*
* @param string $str 所要验证的邮箱地址
* @return boolean
*/
function isEmail($str) {
if (!$str) {
return false;
}
return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $str) ? true : false;
}

 


精彩评论(0)

0 0 举报