Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");}
like image 995
Loop Masters Avatar asked Dec 21 '22 20:12

Loop Masters


1 Answers

you have two choices to use

  • JFormattedTextField with proper Formatter or InputVerifier

  • use DocumentFilter


  • notice don't use String Text; (possible reserved word for API name or its method) use String text; more in the Naming convention
like image 101
mKorbel Avatar answered Jan 03 '23 16:01

mKorbel