Java验证是否为纯数字 package rbq.codedemo;import java.util.regex.Pattern;/** * Created by rbq on 2016/12/13. */public class NumUtils { public static boolean isNum(String str){ Pattern pattern = Pattern.compile("^-?[0-9]+"); if(pattern.matcher(str).matches()){ //数字 return true; } else { //非数字 return false; } } public static boolean isNum1(String str){ //带小数的 Pattern pattern = Pattern.compile("^[-+]?[0-9]+(\\.[0-9]+)?$"); if(pattern.matcher(str).matches()){ //数字 return true; } else { //非数字 return false; } }} 转载于:https://www.cnblogs.com/aeon/p/10162494.html