最後生還者The Last of Us Part II 開售日決定   超級瑪利歐兄弟35週年!JR東日本電車內的瑪利歐雜學問答影片大更新!   「CODE:D-BLOOD」登陸日本 乃木坂白石麻衣成CM主角*内有影片   從筆刷到劍刃:《Ghost of Tsushima》的概念藝術揭密   UNIQLO與MINECRAFT合作 推出系列T-Shirt!   小型光學遊戲滑鼠Razer DeathAdder V2 Mini發表   日本首次VALORANT職業循環賽「VALORANT Mildom Masters」開始!   可在今天獲得內含新遊戲 + 的《漫威鋼鐵人VR》免費修補程式更新 

PHP 符合 RFC 規範的 Email 驗證程式

要驗證 Email 是否符合規格, 大部分是使用下面的簡單 Regular expression 來作驗證 (下面兩者 regex 是一樣的, 只是 php / rails 版的寫法而已)

使用上述的檢查後, 再加上 PHP 驗證 Email -檢查 DNS 的 MX 是否有通, 再來就該直接寄信去驗證了.

在前面那段 regex 的驗證, Dominic Sayers 把 RFC 1123, 2396, 3696, 4291, 4343, 5321 & 5322 看完, 寫出下面的 PHP function, 此 function 也有附上 unit test 的測試資料, 是我看過最複雜的檢查了. XD

轉載此 Function: (Source: RFC-compliant email address validator)

描述: A PHP function that validates all parts of a given email address, according to RFCs 1123, 2396, 3696, 4291, 4343, 5321 & 5322. I’ve released it under a license that allows you to use it royalty-free in commercial or non-commercial work, subject to a few conditions. It’s almost certainly the first email address validator that correctly lets you put an IPv6 address in for the domain part.

Source

相關文章