确认密码字段不起作用

时间:2016-12-12 07:45:48

标签: android

我正在尝试匹配两个密码字段但其显示密码不匹配

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

3 个答案:

答案 0 :(得分:4)

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. 首先检查 equals("")
  2. _repasswordText.getText()。toString()
  3. 之前添加!符号

答案 1 :(得分:1)

您应该在

之前添加!
_repasswordText.getText().toString().equals(_passwordText.getText().toString())

答案 2 :(得分:1)

您可以使用_repasswordText.getText().toString().contentEquals(_passwordText.getText().toString())