2

why default EditText for email isn't validating an email Address?as EditText field is working for number input.i know that we can validate it by using java.util.regex.Matcher and java.util.regex.Pattern is there any default function as for number is?

inputtype="textEmailAddress" is not working as inputType="number" do work...

Last Warrior
  • 1,307
  • 1
  • 11
  • 20

3 Answers3

2

Editext field will not validate your email only by setting it's input method to email type.

You need to validate it yourself.

Try this:

Android: are there any good solutions how to validate Editboxes

email validation android

Community
  • 1
  • 1
Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
0

You can do any type of validation in android very easily by the oval.jar file. OVal is a pragmatic and extensible general purpose validation framework for any kind of Java objects.

follow this link: http://oval.sourceforge.net/userguide.html

You can downlaod this from here: http://oval.sourceforge.net/userguide.html#download

You can use validation by setting tags in variables

public class Something{

    @NotEmpty  //not empty validation
    @Email     //email validation
    @SerializedName("emailAddress")
    private String emailAddress;
}

   private void checkValidation() {
        Something forgotpass.setEmailAddress(LoginActivity.this.dialog_email.getText().toString());
        Validator validator = new Validator();
        //collect the constraint violations
        List<ConstraintViolation> violations = validator.validate(forgotpass);
        if(violations.size()>0){
            for (ConstraintViolation cv : violations){
                if(cv.getMessage().contains("emailAddress")){
                    dialog_email.setError(ValidationMessage.formattedError(cv.getMessage(), forgotpass));
                }
            }
        }
}
Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
0

Please use below code for that, it will solve your problem.

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;
}

And see below Stack Overflow link for more information.

Email Validation

Community
  • 1
  • 1
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128