WEB教程基地:www.91ctc.com为你搭建学习WEB技术的优秀平台
在线留言 网站地图 加入收藏 设为首页
您的位置:本站首页>>PHP>>PHP验证邮箱地址是否合法,PHP正则表达式验证Email地址

PHP验证邮箱地址是否合法,PHP正则表达式验证Email地址

[ 录入者:91ctc | 时间:2015-05-14 23:19:19 | 作者: 91ctc| 来源:本站 | 浏览: 次 ]


使用PHP验证用户输入的电子邮箱是否合法,正则表达式写法如下:

$pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";

那么,只需要:

PHP Code复制内容到剪贴板
  1. $email = strip_tags(trim($_POST["email"]));  
  2. $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";  
  3. if($email==""){  
  4.    echo "<div align='center'><font color=red size='2pt'>Please enter the email</font></div>";  
  5.    $check = false;  
  6. }else{  
  7. if(!preg_match($pattern,$email)){  
  8.    echo "<div align='center'><font color=red size='2pt'>Please make sure your email address is correct,otherwise the recipient will not be able to reply</font></div>";  
  9.    $check = false;  
  10.    }  
  11. }  

即可。


关闭】【返回顶部

相关文章
{xiangguan_list}
91ctc.com 网络先锋,引领科技,本站原创作品[转载请注明出处]。联系我们
Copyright© 2010-2017 计算机教程中心网 . All rights reserved. 苏ICP备11081842号