Deepak
Deepak

Reputation: 197

Confirm password field not working

I am trying to match two field that is of password but its showing password do not match

 else if (_passwordText.getText().toString().equals("") || _passwordText.length() < 4 || _passwordText.length() > 10) {
        AlertDialog alertDialog = new AlertDialog.Builder(Register.this).create();
        alertDialog.setTitle("oops!");
        alertDialog.setMessage("Password  field is empty");
        alertDialog.show();
    }


   else if (_repasswordText.getText().toString().equals(_passwordText.getText().toString())) {
        AlertDialog alertDialog = new AlertDialog.Builder(Register.this).create();
        alertDialog.setTitle("oops!");
        alertDialog.setMessage("Passwords do not match");
        alertDialog.show();
        }

Upvotes: 0

Views: 106

Answers (3)

Shalauddin Ahamad Shuza
Shalauddin Ahamad Shuza

Reputation: 3657

You can use _repasswordText.getText().toString().contentEquals(_passwordText.getText().toString())

Upvotes: 0

Kingyal
Kingyal

Reputation: 63

You should add ! before

_repasswordText.getText().toString().equals(_passwordText.getText().toString())

Upvotes: 1

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

else if (_passwordText.getText().toString().equals("")  {
        AlertDialog alertDialog = new AlertDialog.Builder(Register.this).create();
        alertDialog.setTitle("oops!");
        alertDialog.setMessage("Password  field is empty");
        alertDialog.show();
    }


   else if (!_repasswordText.getText().toString().equals(_passwordText.getText().toString())) {
        AlertDialog alertDialog = new AlertDialog.Builder(Register.this).create();
        alertDialog.setTitle("oops!");
        alertDialog.setMessage("Passwords do not match");
        alertDialog.show();
        }

FYI

  1. At first check equals("")
  2. Add ! sign before _repasswordText.getText().toString()

Upvotes: 4

Related Questions