Well, it's simple. By the code that you put and by JOPtionPane I see that you are working with Java SE.
You can create a method to validate if the user input contains text only (for text it means only alphabetic characters) through regex.
Regular Expression (regex) is nothing more than a string that defines a search pattern in Strings, you can create expressions to validate a myriad of patterns, such as emails, cpfs, etc. to know more .
I'll give you two options of expressions to start your studies on the subject and help you reach the goal.
The first: "[a-zA-Z \ s] +" In this you will only validate lowercase letters (az), uppercase letters ). The + character indicates that this combination can occur 1 or more times. Check out the example applied here http: // regexr.com/3cd9n, as you will realize this expression will not accept special characters or accents and in case you want them to be accepted let me search for it yourself, a link to get started.
The second: "[^ \ d] +" This expression is easier if you just do not want to accept numbers and want to accept any other character type. The ^ character is used to deny the character \ d indicating the digits. See the example in practice http: // regexr.com/3cd9q.
To apply in Java you only need a String to be able to call the class matches method, see an example method:
public boolean matchesOnlyText(String text) {
return text.matches("[^\d]+"); //Passa para o método matches a regex
//Se tiver número na string irá retornar falso
//Note o uso de duas \, uma sendo obrigatória para servir de caracter de escape
}
Now according to your own code example, you can do something like:
String nome = JOptionPane.showInputDialog("Qual seu nome ? ");
if(!matchesOnlyText(nome)) {
JOptionPane.showMessageDialog(null, "Você não pode inserir números no nome.");
}
I hope I have helped at least start your regex studies.
Sorry for the broken links, because I can not publish above 2 links, just take the space.
Thanks.