2012-12-26 86 views
2

我試圖找出如何刪除電子郵件地址中的所有無效字符。刪除電子郵件地址中的無效字符

例如:電子郵件=「taeo͝'; [email protected]」(是電子郵件的字符),將結果應該是:電子郵件=‘[email protected]

我使用以下電子郵件方式:

String email_pattern = "^[^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$]"; 

String modifiedEmail = email.replaceAll(email_pattern,""); 

但上面的代碼是給結果:電子郵件=「[email protected]」,但預計「[email protected]

任何建議或更好的方法,將不勝感激。

+0

什麼是錯了[Unicode的電子郵件地址(http://stackoverflow.com/questions/3844431/are-email-addresses-allowed-to-contain-non-alphanumeric-characters)? – 2012-12-26 22:01:56

回答

0

我通過使用模式匹配器解決了它。

email = "testo͝';@.com.my" 
String EMAIl_PATTERN = "[^a-zA-Z0-9!#$%&@'*+-/=?^_`{|}~.]+"; 
modifiedEmail = email.replaceAll(EMAIl_PATTERN, ""); 
0

進一步的思考: 你也可以用於測試無需驗證(例如http://trashmail.com/)使用的電子郵件不會忽略的知識提供者。

相關問題