1 /** 2 * 判断是否为数字(正负数都行) 3 * @param str 需要验证的字符串 4 * @return 5 */ 6 public static boolean isNumeric(String str){ 7 Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); 8 Matcher isNum = pattern.matcher(str); 9 if( !isNum.matches() ){ 10 return false; 11 } 12 return true; 13 }