Question: 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");}

```

Answer: 
you have two choices to use

* [JFormattedTextField](http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html) with proper `Formatter` or `InputVerifier`
* use [DocumentFilter](https://stackoverflow.com/a/9430683/714968)

---

* notice don't use `String Text;` (possible reserved word for API name or its method) use `String text;` more in the [Naming convention](http://en.wikipedia.org/wiki/Naming_convention_%28programming%29)
Addition: You could do it also like the following, though i recommend mKorbel's answer.

```
try  {
    System.out.println(Integer.parseInt(Text) + "is a valid input.");
} catch (Exception e) {
    System.out.println("The input "+ Text + "is invalid");
}

```