/**
* 匹配是否為數字
* @param str 可能為中文,也可能是-19162431.1254,不使用BigDecimal的話,變成-1.91624311254E7
* @return
* @author yutao <<<<<<<<<<<<<<<<<<<<<<<<<作者
* @date 2016年11月14日下午7:41:22
*/
public static boolean isNumeric(String str) {
// 該正則表達式可以匹配所有的數字 包括負數
Pattern pattern = Pattern.compile("-?[0-9]+(\\.[0-9]+)?");
String bigStr;
try {
bigStr = new BigDecimal(str).toString();
} catch (Exception e) {
return false;
}
Matcher isNum = pattern.matcher(bigStr); // matcher是全匹配
if (!isNum.matches()) {
return false;
}
return true;
}