Sunday

How to validate email in Android

Validate is important aspect in any programming language. Here I describes how to validate in android.

In your Input Field of email in EditText Field :

String userEmail="androidpoko@gmail.com";
if (!Validate.checkEmail(userEmail)){
String message = "Correct email address";
Toast.makeText(getApplicationContext(), message, TOAST_TIME).show();
}
else {
String message = "Invalidate type email address";
Toast.makeText(getApplicationContext(), message, TOAST_TIME).show();
}

and Validate Class:

public class Validate {

public final static Pattern EMAIL_ADDRESS_PATTERN = 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}" +
            ")+"
        );
 public static boolean checkEmail(String email) {
        return EMAIL_ADDRESS_PATTERN.matcher(email).matches();
    }
}

Happy Coding !!!

0 comments

Posts a comment

Related Posts  www.prandroid.com...
 
© 2011 Android Programming Tutorails | 2012 Templates
Designed by Blog Thiết Kế
Back to top