Skip to content

Instantly share code, notes, and snippets.

@nishantkp
Created April 13, 2018 00:33
Show Gist options
  • Save nishantkp/5ca57d124396e993087948d12b0d8bb3 to your computer and use it in GitHub Desktop.
Save nishantkp/5ca57d124396e993087948d12b0d8bb3 to your computer and use it in GitHub Desktop.
Validate user-email and password before performing login operation
/**
* Validate user email and password
* Email and password EditText fields are wrapped inside TextInputLayout
*
* @return true if email and password are valid, otherwise false
*/
private boolean isCredentialsValid() {
String emailAddress = edtEmail.getText().toString().trim();
String password = edtPassword.getText().toString();
if (TextUtils.isEmpty(emailAddress)
|| !android.util.Patterns.EMAIL_ADDRESS.matcher(emailAddress).matches()) {
edtEmailWrapper.setError("Enter valid email!");
return false;
} else if (TextUtils.isEmpty(password)) {
edtPasswordWrapper.setError("Enter password");
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment