Java String – See if a string contains only numbers and not letters
If you’ll be processing the number as text, then change: if (text.contains(“[a-zA-Z]+”) == false && text.length() > 2){ to: if (text.matches(“[0-9]+”) && text.length() > 2) { Instead of checking that the string doesn’t contain alphabetic characters, check to be sure it contains only numerics. If you actually want to use the numeric value, use Integer.parseInt() … Read more