'How to print error massage when a given password is above 8 characters in java

String Password = new String(pw.getPassword());
Pattern pp=Pattern.compile("[a-zA-Z0-9]{8}");
Matcher pm= pp.matcher(Password);
if(pm.find()){
String ConfirmPassword = new String(cpw.getPassword());
}
else{
JOptionPane.showMessageDialog(null,"  Wrong Password; \npassword should type 8 characters" , "Error", JOptionPane.ERROR_MESSAGE);

pw.requestFocus();
pw.selectAll();

}

I want to print error massage when i type password above 8 characters.How can i change this code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source