public static boolean isValidNumber(String str) { Pattern pattern = Pattern.compile("^[-\+]?[.\d]*$"); return pattern.matcher(str).matches(); }