首页 > 其他 > 详细

PhoneUtils

时间:2017-02-23 19:49:24      阅读:260      评论:0      收藏:0      [点我收藏+]
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneUtils {
   /**
    * @param phoneNo
    *            加星号过的电话号码
    */
   public static String dealPhoneNo(String phoneNo) {
      return phoneNo.substring(0, 3) + "****" + phoneNo.substring(7);
   }

   /**
    *  通过正则表达式判断是否为手机号
    * @param phoneString
    * @return
    */
   public static boolean isPhoneNumber(String phoneString) {
      String format = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
      return isMatch(format, phoneString);
   }

   /**
    *  字符串正则校验
    * @param regex
    *            正则表达式
    * @param string
    *            需要检验的字符串
    * @return
    */
   public static boolean isMatch(String regex, String string) {

      Pattern pattern = Pattern.compile(regex);
      Matcher matcher = pattern.matcher(string);
      return matcher.matches();
   }
}

 

PhoneUtils

原文:http://www.cnblogs.com/loaderman/p/6435098.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!