title: How to validate Password Field in android?
body: <p>Hi I am very new for android and in my app I have Validations for Change password page.</p>
  
  <p>That means the Password must contain minimum 8 characters at least 1 Alphabet, 1 Number and 1 Special Character, for this I tried the code below, but it's not working.</p>
  
  <p>Please help me.</p>
  
  <pre><code>if(!isPasswordValidMethod(newPassword.getText().toString())){
             System.out.println("Not Valid");
  
                  }else{
  
          System.out.println("Valid");
      }
  
  
  
       // Validate password
          private boolean isPasswordValidMethod(String password) {
  
              String yourString = newPassword.getText().toString();
  
              System.out.println("yourString is =" + yourString);
  
              boolean isValid = false;
  
              // ^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
              // ^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$
  
              String expression = "^(?=.*[A-Za-z])(?=.*\\\\d)(?=.*[$@$!%*#?&amp;])[A-Za-z\\\\d$@$!%*#?&amp;]{8,}$";
              CharSequence inputStr = password;
  
              Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
              Matcher matcher = pattern.matcher(inputStr);
              if (matcher.matches()) {
                  System.out.println("if");
                  isValid = true;
              }else{
                  System.out.println("else");
              }
              return isValid;
          }
  </code></pre>