国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 化隆| 延津县| 班玛县| 鹤峰县| 鲜城| 马鞍山市| 靖州| 景宁| 阿拉善右旗| 交口县| 大田县| 鹤峰县| 廊坊市| 花莲县| 北流市| 玛多县| 乾安县| 左贡县| 紫金县| 嘉荫县| 江津市| 阿拉善盟| 泾源县| 依兰县| 炎陵县| 凉城县| 九龙县| 彭水| 定日县| 丹棱县| 开平市| 铜陵市| 商都县| 盐源县| 湖州市| 西畴县| 芒康县| 钦州市| 平顶山市| 外汇| 芒康县|