手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

java验证电话手机

时间:2024-10-12 07:19:07

1、打开MyEclipse,然后新建类“Test”

java验证电话手机

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; }

java验证电话手机

3、编写测试方法mian,代码如下:public static void main猾诮沓靥(String[] args) { Test t = new Test(); System.泠贾高框out.println(t.isPhone("18710622658")); }

java验证电话手机

4、运行mian方法结果:true

java验证电话手机
© 手抄报圈