0

I am developing an app in which I have some edit Text and some validation on them but when I enter "JJJJ@GMAil.cOM" it except and also for "JJJJ@JJj.com". how do I do validation for that here is code:-

public boolean validation(String mobile, String pass) {

    if (mobile != null && mobile.length() > 7 && mobile.length() < 15) {
        if (pass.length() >= 4 && pass.length() <= 8) {
            return true;
        } else {
            m_InputPassword.setError("Password must be between 4 to 8 characters long");
            return false;
        }
    } else {
        m_InputMobile.setError("Mobile number must be between 7 to 15 characters long");
        return false;
    }
}   

private boolean isValidEmail(String email) {

    String regExpn = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@" + "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
            + "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" + "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";
    CharSequence inputStr = email;
    Pattern pattern = Pattern.compile(regExpn, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches())
        return true;
    else
        return false;
}
ArK
  • 20,698
  • 67
  • 109
  • 136
John
  • 7
  • 7

1 Answers1

0

You can create a boolean field for every EditText associated, so now you can do the validation and set one of this booleans to true if there was an error, then you just you'll has to set an OnClickListener() for every EditText and if one of this has its associated boolean to true, set the error for it inside listener.

Ricard
  • 1,223
  • 1
  • 13
  • 17