Well that's my question, I'm doing a form in java swing and when filling in the fields of the JTextField I want to launch an error window in case it contains some numeric character. I have been testing many things but I have not reached anything. I am currently caught here:
if (labor.isEditable()) { //Este if es porque dependiendo del usuario
try { //que introduzca, habrá casillas en las que pueda escribir o no
Integer.parseInt(labor.getText().toString()); //En el caso de que esto lance una excepción significara que la conversión no se ha realizado y por tanto es un String
JOptionPane.showMessageDialog(null, "La labor NO PUEDE tener contenido numerico");
labor.setText(""); //Pongo en blanco el campo del JTextField
valido = false;
} catch (NumberFormatException e) {
valido = true; //Verifico de que el contenido es correcto
}
}
I've been doing tests and there are times that if I detect it and it shows me the error message in these cases:
-
If I put a String that starts with a number: Ej == > "43sgfdlgfd"
-
If I put a number. Ej == > "32214", "23532" ...
But I can not get it to work if it starts with a letter and contains some numerical character in the middle of Labor == > "Clean Cr124istales".
Any idea how I can do ???
Thank you very much everyone.