java验证电话手机
1、打开MyEclipse,然后新建类“Test”

2、在Test类中,编写验证电话号码的方法,代码:
/**
* 判断是否是电话
* @param phone
* @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

阅读量:65
阅读量:34
阅读量:47
阅读量:118
阅读量:36