本文介紹了如何檢查edittext的文本是否為電子郵件地址?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何在不使用 javascript
和正則表達式的情況下檢查 edittext
的文本是否為電子郵件地址?在這里,我使用了 inputtype="textEmailAddress"
這可以正常工作,但沒有顯示錯誤消息.
how to check the text of edittext
is email address or not without using javascript
and regular expression?
Here I used inputtype="textEmailAddress"
this is working but no error message is display.
推薦答案
/**
* method is used for checking valid email id format.
*
* @param email
* @return boolean true for valid false for invalid
*/
public static boolean isEmailValid(String email) {
String expression = "^[\w\.-]+@([\w\-]+\.)+[A-Z]{2,4}$";
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
在此函數中傳遞您的編輯文本字符串.
Pass your edit text string in this function .
對于正確的電子郵件驗證,您需要服務器端身份驗證
for right email verification you need server side authentication
注意現在 Android 中有一個內置方法,請參閱下面的答案.
Note there is now a built-in method in Android, see answers below.
這篇關于如何檢查edittext的文本是否為電子郵件地址?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!