-1
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.

  • You have `String Password = new String(pw.getPassword())`. So... Just check if `Password.length() > 8`? – JustAnotherDeveloper May 11 '22 at 15:51
  • Can you just use `String.length()`? If you want to use your regex you can use this answer https://stackoverflow.com/questions/9043820/regex-to-match-words-of-a-certain-length – rhowell May 11 '22 at 15:52
  • Use matches instead of find? – RealSkeptic May 11 '22 at 16:29
  • 1
    Also, FWIW, limiting password length is counter productive as far as security is concerned. The same for limiting the character domain. The longer and the more "weird" characters a password has, the better. – RealSkeptic May 11 '22 at 16:30
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 11 '22 at 18:24

0 Answers0