php正则表达式验证邮箱

邮箱验证代码大都是不能验证一个字母的域名或一个字母的用户名,如:i@phpfensi.com 或 i@phpfensi.net,解决方法如下:

1,不做总长度判断,长度判断可以自己加上;2,支持.net.cn,.com.cn这样的域名后缀;3,邮箱名部分以字母或者数字开头,中间可以有“-”与“_”符号;4,域名部分以字母或者数字开头,中间可以有“-”与“_”符号;

PHP 邮箱验证正则表达式,代码如下:

preg_match("/^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{2,4}$/i",$email );

实例代码如下:

  1. /**  
  2.  * 自己修整的一个邮箱正则表达式  
  3.  * php粉丝网  
  4.  */ 
  5. echo '<meta charset="utf-8" />';  
  6. function c_email($email){  
  7.     $reg='/^([a-zA-Z0-9]{1,20})(([_-.])?([a-zA-Z0-9]{1,20}))*@([a-zA-Z0-9]{1,20})(([-_])?([a-zA-Z0-9]{1,20}))*(.[a-z]{2,4}){1,2}$/';  
  8.     if(preg_match($reg,$email))  
  9.         return true;      
  10.     return false;  
  11. }  
  12. $email = 'mail@lizhong.me';  
  13. $check_result = c_email($email);  
  14. if($check_result){  
  15.     echo '邮箱格式正确';  
  16. }else{  
  17.     echo '邮箱格式错误';  

邮箱验证类,代码如下:

  1. <?php 
  2. class Reg 
  3.     public $mail
  4.     function __construct() 
  5.     { 
  6.         $this->mail = $_POST["mail"];         
  7.     } 
  8.     function RegMail() 
  9.     { 
  10.         if(preg_match("/^[0-9a-zA-Z]+(?:[_-][a-z0-9-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*.[a-zA-Z]+$/i"$this->mail)) 
  11.         { 
  12.             echo "<script language='javascript'>alert('验证成功')</script>"
  13.         } 
  14.         else 
  15.         { 
  16.             echo "<script language='javascript'>alert('验证失败')</script>"
  17.         } 
  18.     } 
  19. $r = new Reg(); 
  20. $r->RegMail(); 
  21. $strings = "abc@163.com"
  22. if(preg_match("/^[0-9a-zA-Z]+(?:[_-][a-z0-9-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*.[a-zA-Z]+$/i",$strings)) 
  23.     echo"验证成功!是邮箱地址。"
  24. else 
  25.     echo"不是邮箱地址!"
  26. ?>
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » php正则表达式验证邮箱

99 评论

  1. cialis ohne rezept tadalafil generika viagra 50mg kaufen für männer

  2. buy doxycycline for sale buy generic lasix order generic furosemide 100mg

  3. prograf ca urso 300mg ca order ursodiol without prescription

  4. azithromycin 250mg without prescription zithromax 500mg usa cost neurontin 800mg

  5. oral domperidone 10mg buy sumycin sale purchase cyclobenzaprine generic

  6. flomax over the counter aldactone canada order spironolactone 25mg

  7. order tadalafil 20mg without prescription sildenafil 50mg viagra 50mg cheap

  8. deltasone 10mg price buy deltasone purchase mebendazole

  9. online gambling for real money casino slot live online blackjack

  10. order nifedipine 10mg without prescription adalat ca allegra canada

  11. buy esomeprazole 40mg pill nexium generic brand furosemide

  12. order ditropan 5mg generic buy prograf 1mg pills buy trileptal 300mg without prescription

  13. cialis 40mg ca buy tadalafil how to buy ed pills

  14. catapres 0.1mg over the counter spiriva 9 mcg cost tiotropium bromide 9 mcg for sale

  15. buy isotretinoin 10mg zithromax 500mg sale order azithromycin 500mg without prescription

  16. clobetasol oral cost clobetasol how to get amiodarone without a prescription

发表评论

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡