简单的整数或者小数判断正则表达式

2017-08-27  本文已影响11人  一一小知
/**
 * 正则表达式规则:-号出现0或者1次,0-9出现多次,小数点出现0或者1次,0-9出现多次
 * @param str
 * @return
 */
public static boolean isNumeric(String str) {
    if (str != null && !str.isEmpty()) {
        Pattern pattern = Pattern.compile("-?[0-9]*.?[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (isNum.matches()) {
            return true;
        }
    }
    return false;
}
上一篇 下一篇

猜你喜欢

热点阅读