Search code examples
javastringswingnetbeans-7jtextfield

Making a String accept only letters ( no numbers ).


Is it possible to allow only letters or numbers in a string in java ? for example :

String Text;
Text = jTextField1.getText();

now

if (Text is a number) {System.out.println("Invalid Input");}

Solution

  • you have two choices to use


    • notice don't use String Text; (possible reserved word for API name or its method) use String text; more in the Naming convention