PHPã§ã¡ã¼ã«ã¢ãã¬ã¹ã確èªãããæ£ããæ¹æ³ã(Linux Journalèªã®è¨äºãã)
æ¬å±ã§ç«ã¡èªã¿ãã¦ãããLinux Journalã£ã¦éèªã« "Validate an E-Mail Address with PHP, the Right Way" ã£ã¦è¨äºãè¼ã£ã¦ããã®ãçºè¦ããã®ã§ãç°¡åã«è¦ç´ãã
ã¾ãã以ä¸ã®ã¡ã¼ã«ã¢ãã¬ã¹ã¯ãæ£ãããã¢ãã¬ã¹ã§ãããã¨ç´¹ä»ã
- Abc\@def@example.com
- customer/department=shipping@example.com
- !def!xyz%abc@example.com
ããã¯ãRFC3696ããã®å¼ç¨ã
RFC3696ã¯ãApplication Techniques for Checking and Transformation of Names
(ååã®æ¤æ»ã¨å¤æã®ã¢ããªã±ã¼ã·ã§ã³ææ³) ã£ã¦ãã¤ã§ããã®ãªãã«ã "Restrictions on email addresses" ã£ã¦ç« ãããã¿ããã
ç¶ãã¦ãä¾ã¨ãã¦
http://www.devshed.com/c/a/PHP/Email-Address-Verification-with-PHP/2/
ãæãã
function checkEmail($email) { if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@é·ããã§ããã§æ¹è¡å ¥ãã¾ãã ( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)){ list($username,$domain)=split('@',$email); if(!checkdnsrr($domain,'MX')) { return false; } return true; } return false; }
ãã®é¢æ°ã®ééã£ã¦ãã¨ãããææã
æ£è¦è¡¨ç¾ã足ããªãã®ã¯ããããããããããã ãã©ãDNSã®ãã§ãã¯ããããããMXã¬ã³ã¼ããå¿ ãããã¨ã¯éããªããããã¨ãæ¸ãã¦ããã(symfonyã®ã¯ãã¡ããã¨èª¿ã¹ã¦ãã¿ããã )
ããã«
http://www.ilovejackdaniels.com/php/email-address-validation/
ã®ã¹ã¯ãªãããç´¹ä»ã
ãã®ã¹ã¯ãªããã®èè Daveæ°ã¯ãRFC2822ããã¡ãã¨èªãã§validãªã¡ã¼ã«ã¢ãã¬ã¹ã® "local-part" ãã1æåãã64æåã§ãããã¨ãç解ãã¦ãããã¨ç´¹ä»ã
ãã®ã¹ã¯ãªããã®"the only major flaw" ã¯ãã¦ã¼ã¶ã¼åä¸ã«ã \@ ãå«ã¾ããã¨ããã¾ãå¦çã§ããªããã¨ãããã
ã§ããã®ãã¨ãé¢ç½ãã¦ããæ£ããã¡ã¼ã«ã¢ãã¬ã¹ã®æ¡ä»¶ã10ãæ¡ããRFCã®åç §ä»ãã§ç´¹ä»ããã¦ããã
- ã¡ã¼ã«ã¢ãã¬ã¹ã¯ local part 㨠domain ã @ ã§åºåããã¦æ§æããã¦ããã(RFC2822)
- local partã¯ãã¢ã«ãã¡ããããæ°åã以ä¸ã®è¨å· ! # $ % & ' * + - / = ? ^ _ ` { | } ~ ã§ããããã . ãã§åºåããã¦ããå ´åãããããã ããæåãæå¾ãä»ã®ãããã®é£ã«ãã£ã¦ã¯ãããªãã(ã¤ã¾ãé£ç¶ããªããã¨ã¨ãããã¨ã) (RFC2822 3.2.4)
- local partã¯ã ã¯ãªã¼ãã¼ã·ã§ã³ãã¼ã¯ã " ãã®ãªãã«ã¹ãã¼ã¹ãå«ãããããªæåãå ¥ã£ã quoted string ãå«ããã¨ããã (RFC2822 3.2.5)
- \@ ãªã©ã® "quoted pair" ãlocal partã«å«ããã®ããæ£ãããã "obsolete" (RFC822ãRFC2822 4.4) (RFC2822ã¯RFC822ãsupersedeãã¦obsoleteã«ãããã¨ãã)
- local partã®æ大é·ã¯ 64æå (RFC2821 4.5.3.1)
- domainã¯ãlabelããããã§åºåããããã®ã§ãã (RFC1035 2.3.1)
- domainã¯ãã¢ã«ãã¡ãããã§å§ã¾ãããã®å¾ã«ã0æå以ä¸ã®ã¢ã«ãã¡ããããæ°åããã¤ãã³ã - ããç¶ããæå¾ã®ä¸åã¯ã¢ã«ãã¡ããããæ°åã(RFC1035 2.3.1)
- labelã®æ大é·ã¯ 63å (RFC1035 2.3.1)
- domainã®æ大é·ã¯ 255å (RFC2821 4.5.3.1)
- domainã¯ãfully qualifiedã§ãDNSã®type Aãããã¯MXã¬ã³ã¼ãã§resolvableã§ãªããã°ãªããªã (RFC2821 3.6)
ãã§ããã®ãã¨3ãã¼ã¸ã«ããã£ã¦ãè²ã 解説ããªãããPHPã«ããã¡ã¼ã«ã¢ãã¬ã¹æ¤è¨¼é¢æ°ãå®éã«ä½ã£ã¦ããã(ãããããã«åãã®ã¯ãé¢åãªã®ã¨ã¡ãã£ã¨æªããããªæ°ãããã®ã§çç¥ãã¾ããããå¸æããããããªãèãã¾ã)
ã¾ããè¨äºã®æå¾ã«é¢ç½ããã¨ãæ¸ãã¦ãããã ãã©ã ä¸éã®ã¡ã¼ã«ã¢ãã¬ã¹æ¤è¨¼ã¯çµæ§ããå æ¸ã ãã¦ãã¨ã¯ã spamãããããã«ã {^c\@**Dog^}@example.com ã¨ãã£ãã¡ã¼ã«ã¢ãã¬ã¹ã使ããããããªãããã¨ããææ¡ã
ãããwebãã¼ã¸ã«ç»åã§ã¡ã¼ã«ã¢ãã¬ã¹ãè¼ããããããã©ã(ã¢ã³ã«ã¼ã¿ã°ã¯ããã«)ãã®ãããªã¡ã¼ã«ã¢ãã¬ã¹ãæåã§è¼ãã¦ããã°ã人éã¯ã³ããã§ãã¦æ¥½ã ãããããã¯æ£ããèªèããªãå¯è½æ§ãé«ãã®ã§å®å ¨ãããªãã? ã¿ãããªã
â¦â¦å¾®å¦ããªã
ä»åã
â
â
re: PHPでメールアドレスかどうか調べる方法 (ハズレ日記)
ã¨è©±é¡ãé²ãã§ãã¦(ç´¹ä»æ¼ãããã£ããããããªãã) ã¡ãã£ã¨æã£ããã ãã©ã メールアドレスに一致する正規表現ã«ããã¡ã¼ã«ã¢ãã¬ã¹ã«ä¸è´ããæ£è¦è¡¨ç¾ã¯ãããã¾ããããã£ã¦æ¸ãã¦ãããã©ãããããã¨ããã¯ãªã¼ãããã°ãªãã§ãå ¥ããããã£ã¦è©±ã§ãããã
(ãã®ã¯ã½é·ãæ£è¦è¡¨ç¾ã¦ã確ããOreillyã® "Perl in a Nutshell" ããªã«ãã«è¼ã£ã¦ãããããªæ°ããããã ãã©ãæããèªãã§ãã¸ã¼ãã¡ã¼ã«ã¢ãã¬ã¹ã®æ¤è¨¼ã£ã¦å¤§å¤ãªãã ãªã¼ã¨æã£ããã ãã©)
ã§ãä»åã®è¨äºèªãã§ãããç¨åº¦ç¾å®çãªç·ã§ã¡ããã¨ããæ¤è¨¼ããæ¹æ³ããããã ãªã¼ã¨ãæãã¾ããã(DNSã¯ã²ããã§ããããããªæ°ããããã©)
ãã¨ãã¡ãã£ã¨æå¥ã¿ããã«ãªããã©ããã¡ã¼ã«ã¢ãã¬ã¹ã¯ãããã£ã¦æ¤è¨¼ããã°ãããã£ã¦ãµã³ãã«ãç´¹ä»ããã¨ãã¯ãRFCãªã©ã®æ ¹æ ãåºããªãã¨ãã¾ãæå³ããªããããªæ°ãããã(ãã®è¨äºèªãã§ããæã£ããã ãã©)
ãããã¨ä»åèªãã è¨äºã¯ãLinux Journal ã®#158, June 2007å· ã«æ²è¼ããã¦ãããã®ã§ããã