Im really new to java, so i neeed a little help. I know that you can restrict a users input to Integers by throwing a exception if anything other than a Integer is input. But how would you restrict a users input to a string with aplphabetical characters only. Heres my code
Code:
String user = textArea.getText();
if (e.getSource() == button2) {
System.exit(0);
}
if (e.getSource() == button1) {
if (user.length() == 0 ) {
label2.setForeground(Color.BLUE);
JOptionPane.showMessageDialog(null, "Please enter a name", "Alert", JOptionPane.ERROR_MESSAGE);
}else {
this.remove(panel1);
label4.setText("Welcome " + user);
this.add(panel2);
this.pack();
}
}