How to check edittext's text is email address or not?

Dipak Keshariya picture Dipak Keshariya · May 25, 2011 · Viewed 128.1k times · Source

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.

Answer

Pointer Null picture Pointer Null · Feb 10, 2012

On Android 2.2+ use this:

boolean isEmailValid(CharSequence email) {
   return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}

for example:

EditText emailid = (EditText) loginView.findViewById(R.id.login_email);
String getEmailId = emailid.getText().toString();

// Check if email id is valid or not
       if (!isEmailValid(getEmailId)){
        new CustomToast().Show_Toast(getActivity(), loginView,
                "Your Email Id is Invalid.");
 }