首页 > 其他 > 详细

正则匹配电话号码demo

时间:2016-07-28 14:03:42      阅读:254      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!