PHP使用正则判断邮箱是否正确
多的不说直接上代码,正则表达式请看下面变量 $Regex文章地址https://www.yii666.com/learning/php/87.html
1、使用正则方法
/** * 检查是否为电子邮箱 * @param string $value 邮箱地址 * @return boolean */ function isCheckEmail($value) { $Regex = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";; if(preg_match($Regex,$value)) { return true; } else { return false; } }
2、使用php内置方法
文章来源地址:https://www.yii666.com/learning/php/87.html
/** * 检查是否为电子邮箱 * @param string $value 邮箱地址 * @return boolean */ function isCheckEmail($value) { if(!filter_var($value,FILTER_VALIDATE_EMAIL)) { return false; } else { return true; } }
网址:yii666.com