我目前使用這個表達式在我的PHP腳本來驗證電子郵件地址:正則表達式類型的區別?
preg_match_all("/[\._a-zA-Z0-9-][email protected][\._a-zA-Z0-9-]+/i", $string, $matches);
問題是,這個特定的正則表達式是不可靠的,經常發現一些假陽性。
我在看regexlib.com找到一個更好的,但我從那個網站得到的人都沒有找到匹配。
例如:
preg_match_all("^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$", $string, $matches);
覺得沒有什麼,即使它應該根據regexlib工作。我已經嘗試了regexlib中用於電子郵件驗證的前10個正則表達式,並且它們都不起作用。難道我做錯了什麼?
鏈接regexlib電子郵件分類:http://regexlib.com/DisplayPatterns.aspx?cattabindex=0&categoryId=1
感謝,