码迷,mamicode.com
首页 > 其他好文 > 详细

正则匹配电话号码demo

时间:2016-07-28 14:06:37      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:

 1 public static String doFilterTelnum(String sParam) {
 2         String result = sParam;
 3         if (sParam.length() <= 0)
 4             return "";
 5         /*电话号码匹配规则"((13\\d{9})|(15[0,1,2,3,5,6,7,8,9]\\d{8})|(18[0,1,2,5,6,7,8,9]\\d{8})|(147\\d{8}))$*"*/
 6         Pattern pattern = Pattern.compile("(1|861)(3|5|7|8)\\d{9}$*");
 7         Matcher matcher = pattern.matcher(sParam);
 8         StringBuffer bf = new StringBuffer();
 9         while (matcher.find()) {
10             bf.append(matcher.group()).append(",");
11         }
12         int len = bf.length();
13         if (len > 0) {
14             bf.deleteCharAt(len - 1);
15         }
16         String middle = bf.toString();
17         String[] tels = middle.split(",");
18         for (int i = 0; i < tels.length; i++) {
19             result = result.replace(tels[i], "");
20         }
21         return result;
22     }

 

正则匹配电话号码demo

标签:

原文地址:http://www.cnblogs.com/wl310538259/p/5714377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!