国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > PHP > 正文

PHP正則驗(yàn)證Email的方法

2024-05-04 23:36:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了PHP正則驗(yàn)證Email的方法,涉及php正則表達(dá)式驗(yàn)證的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP正則驗(yàn)證Email的方法。分享給大家供大家參考。具體如下:

 

 
  1. <?php 
  2. function validateEmail($email
  3. $isValid = true; 
  4. $atIndex = strrpos($email"@"); 
  5. if (is_bool($atIndex) && !$atIndex
  6. $isValid = false; 
  7. else 
  8. $domain = substr($email$atIndex+1); 
  9. $local = substr($email, 0, $atIndex); 
  10. $localLen = strlen($local); 
  11. $domainLen = strlen($domain); 
  12. if ($localLen < 1 || $localLen > 64) 
  13. // local part length exceeded 
  14. $isValid = false; 
  15. else if ($domainLen < 1 || $domainLen > 255) 
  16. // domain part length exceeded 
  17. $isValid = false; 
  18. else if ($local[0] == '.' || $local[$localLen-1] == '.'
  19. // local part starts or ends with '.' 
  20. $isValid = false; 
  21. else if (preg_match('///.//./'$local)) 
  22. // local part has two consecutive dots 
  23. $isValid = false; 
  24. else if (!preg_match('/^[A-Za-z0-9//-//.]+$/'$domain)) 
  25. // character not valid in domain part 
  26. $isValid = false; 
  27. else if (preg_match('///.//./'$domain)) 
  28. // domain part has two consecutive dots 
  29. $isValid = false; 
  30. else if(!preg_match('/^(////.|[A-Za-z0-9!#%&`_=///$/'*+?^{}|~.-])+$/'str_replace("////","",$local))) 
  31. // character not valid in local part unless  
  32. // local part is quoted 
  33. if (!preg_match('/^"(////"|[^"])+"$/'str_replace("////","",$local))) 
  34. $isValid = false; 
  35. if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) 
  36. // domain not found in DNS 
  37. $isValid = false; 
  38. return $isValid
  39. ?> 

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东源县| 惠东县| 左权县| 西畴县| 白玉县| 从江县| 钟祥市| 广饶县| 北安市| 阿巴嘎旗| 凌源市| 南木林县| 冷水江市| 崇礼县| 营口市| 韶关市| 靖西县| 磐石市| 闽清县| 遂川县| 射洪县| 巫山县| 陇川县| 海丰县| 新巴尔虎左旗| 甘孜| 固镇县| 叶城县| 砀山县| 庆城县| 正镶白旗| 河南省| 贵阳市| 新河县| 伊金霍洛旗| 绥宁县| 罗山县| 马鞍山市| 绵阳市| 崇礼县| 江阴市|