-4

Pattern Matching to validate the entered emailid in Edittext.

Pattern.compile("[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}" + ")+"); 
Varun Vishnoi
  • 980
  • 1
  • 9
  • 32

5 Answers5

3

Try This : It's Running well for me.

Set Input Type "Email" for your Edit Text in XML File.

public void Is_Valid_Email()
        {
        if(Email_Text.getText().toString()!=null)
        {
            if(isEmailValid(Email_Text.getText().toString())==false ) 
            {
                Toast.makeText(getApplicationContext(), "Invalid Email Address ",Toast.LENGTH_LONG).show();
                Valid_Email=null;
            }
            else
            {
                Valid_Email=Email_Text.getText().toString();
            }
        }
        else
        {
            Valid_Email=null;
        }

}// end of email

// Android Provide Default Method To Validate Email Address

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

Enjoy .

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
1

Use below function for validate email Id.

public boolean isValidEmailAddress(String emailAddress)
{  
    String  expression="^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";  
    CharSequence inputStr = emailAddress;  
    Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);  
    Matcher matcher = pattern.matcher(inputStr);  
    return matcher.matches();  
}
Chirag
  • 56,621
  • 29
  • 151
  • 198
1

Change your regular expression with this

"[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]+"

or follow below link for email pattern in java

Email pattern in java

Arvind Kanjariya
  • 2,089
  • 1
  • 18
  • 23
0

Regular expression for EMAIL ADDRESS VALIDATION

static final String EMAIL_PATTERN = 
        "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
  String email = (EditText)findViewById(R.id.edittext);

if(!(_email.matches(EMAIL_PATTERN)))
{
    Toast.makeText(getApplicationContext(),"Email is not valid", Toast.LENGTH_SHORT).show();
}
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • 3
    @VarunVishnoi i think you post question for increase your reputation. Why are you ask for vote your question every time ? – Chirag Nov 01 '12 at 08:30
  • because i need 15 reputation only as minimum... u r right sir... everything is taking time here... i cant chat for my question, i cant post question before 20 minutes. Thats why i m asking to vote me up... but no problem sir i can mange. Thankq – Varun Vishnoi Nov 01 '12 at 08:33
  • 1
    @VarunVishnoi if you want to increase your reputation then give answer to questions !! it takes less time to get more reputation . – Chirag Nov 01 '12 at 08:34
0

Use below method for checking valid email id.

/**
 * 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) {
    boolean isValid = false;

    String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
    CharSequence inputStr = email;

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;
    }
    return isValid;
}
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128