Sprawdzanie tylko liczb, jeśli instrukcja

if (text.matches("[0-9]+"){
   // your operations
}