jtext1.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { string1=jtext1.getText(); if(!string1.substring(0,1).matches("[A-Z]")){ errorReport+=errorUpper; errorDetect=true; } if(!string1.substring(1,string1.length()).matches("[a-z]*")){ errorReport+=errorLower; errorDetect=true; } for (i=0; i<string1.length(); i++){ if (Character.isDigit(string1.charAt(i))) { errorReport+=errorAlpha; errorDetect=true; break; } } if (errorDetect=true){ JOptionPane.showMessageDialog(null, errorReport); } errorDetect=false; errorReport="Error: "; jtext2.requestFocus(); } } );