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 :
In your Input Field of email in EditText Field :
String userEmail="androidpoko@gmail.com";and Validate Class:
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();
}
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