public static void main(String args[]) { Pattern pattern = Pattern.compile("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); Matcher isNum = pattern.matcher("1"); if (!isNum.matches()) { System.out.println("不是数字"); }else{ System.out.println("是数字"); } }