String p="12345"; boolean a=p.matches("\\d*");//任意多数字 boolean b=p.matches("\\d{9}");//恰好9个数字 boolean c=p.matches("\\d{3,}");//至少3个数字 boolean e=p.matches("\\d{3,6}");//至少3个最多9个数字 boolean f=p.matches("[35789]*");//任意多数字但得是[35789]中的一个 boolean d=p.matches("1[35789]\\d{9}");//第一位是1,第二位为[35789],有后面是数字到9位 System.out.println(a); String s="1234567"; boolean qq=s.matches("\\d{6,12}"); String v="123456qqcom"; boolean aa=v.matches("\\w*");//任意多的数字,字母,_ System.out.println(aa); String vv="123456@qq.com"; boolean aaa=vv.matches("\\w{6,12}@\\w{2,6}\\.(com|com\\.cn)"); System.out.println(aaa);