Android Email Validation on EditText

Try following code:

public final static boolean isValidEmail(CharSequence target) {
    return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}

This works fine.


Android Email Validation Simplest way

   String validemail= "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +

                        "\\@" +

                        "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +

                        "(" +

                        "\\." +

                        "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +

                        ")+";

               String emal=email.getText().toString();

                Matcher matcherObj = Pattern.compile(validemail).matcher(emal);



                        if (matcherObj.matches()) {

                               Toast.makeText(getApplicationContext(), "enter 

all details", Toast.LENGTH_SHORT).show();

                        }

                        else 
{
                            Toast.makeText(getApplicationContext(),"please enter 

valid email",Toast.LENGTH_SHORT).show();

                        }

I am posting very simple and easy answer of email validation without using any string pattern.

1.Set on click listener on button....

 button_resetPassword.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            CharSequence temp_emilID=username.getText().toString();//here username is the your edittext object...
            if(!isValidEmail(temp_emilID))
            {
                username.requestFocus();
                username.setError("Enter Correct Mail_ID ..!!");
                     or
                Toast.makeText(getApplicationContext(), "Enter Correct Mail_ID", Toast.LENGTH_SHORT).show();

            }
            else
           {
              correctMail.. 
             //Your action...

           }

         });

2.call the isValidEmail() i.e..

   public final static boolean isValidEmail(CharSequence target)
   {
    if (TextUtils.isEmpty(target))
    {
        return false;
    } else {
        return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
    }
 }

I hope it will helpful for you...


Why not use:

public final static boolean isValidEmail(CharSequence target) {
  return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}

As suggested here.