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 }
