天天看點

判斷字元串是否為正整數 & 浮點小數

/**
 * 判斷字元串是否為數字(正整數和浮點數)
 * @param str
 * @return
 */
public static boolean isNumeric(String str) {
    String reg = "^[0-9]+(.[0-9]+)?$";
    Pattern pattern = Pattern.compile(reg);
    Matcher isNum = pattern.matcher(str);
    if (!isNum.matches()) {
        return false;
    }
    return true;
}      

轉載于:https://www.cnblogs.com/laotan/p/9111051.html

繼續閱讀