1、打开MyEclipse,然后新建类“Test”
2、在Test类中,编写验证电话号码的方法,代码:/** * 判断是否是电话 * @param phon髫潋啜缅e * @return */ public static boolean isPhone(String phone) { Pattern phonePattern = Pattern.compile("^1\\d{10}$"); Matcher matcher = phonePattern.matcher(phone); if(matcher.find()){ return true; } return false; }
3、编写测试方法mian,代码如下:public static void main猾诮沓靥(String[] args) { Test t = new Test(); System.泠贾高框out.println(t.isPhone("18710622658")); }
4、运行mian方法结果:true