public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); if(str.indexOf(".")>0){//判断是否有小数点 if(str.indexOf(".")==str.lastIndexOf(".") && str.split("\.").length==2){ //判断是否只有一个小数点 return pattern.matcher(str.replace(".","")).matches(); }else { return false; } }else { return pattern.matcher(str).matches(); }}
转自:https://blog.csdn.net/weixin_39936341/article/details/83114476