随笔-109  评论-187  文章-25  trackbacks-0

/**
 * user java reg to check phone number and replace 86 or +86
 * only check start with "+86" or "86" ex +8615911119999 13100009999 replace +86 or 86 with ""
 * @param phoneNum
 * @return
 * @throws Exception
 */ 
 protected int checkPhoneNum(String phoneNum) throws Exception {
  
  Pattern p1 = Pattern.compile("^((\\+{0,1}86){0,1})1[0-9]{10}");
  Matcher m1 = p1.matcher(phoneNum);
  if (m1.matches()) {
   Pattern p2 = Pattern.compile("^((\\+{0,1}86){0,1})");
   Matcher m2 = p2.matcher(phoneNum);
   StringBuffer sb = new StringBuffer();
   while (m2.find()) {
    m2.appendReplacement(sb, "");
   }
   m2.appendTail(sb);
   return Integer.parseInt(sb.toString());

  } else {
   throw new Exception("The format of phoneNum "+phoneNum+"  is not correct!Please correct it");
  }

 }

posted on 2006-06-19 11:15 小小程序程序员混口饭吃 阅读(8375) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: