正则匹配电话号码demo

 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     }

 

posted @ 2016-07-28 12:33  夏沫、微凉  阅读(181)  评论(0编辑  收藏  举报