/**
* 判断输入是否是 数字 (正数)
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
for (int i = 0; i < str.length(); i++) {
System.out.println(str.charAt(i));
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
/**
* 判断是否为数字(正负数都行)
*
* @param str 需要验证的字符串
* @return
*/
/* public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
*/
判断是否为数字
最新推荐文章于 2023-08-02 18:56:14 发布