java验证手机号格式

  String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$";
  Pattern p = Pattern.compile(regex);
  Matcher m = p.matcher(registrant_phone);  //registrant_phone  ====  电话号码字段
  boolean isMatch = m.matches();
  if (!isMatch) {
     msg.errorCode = 1;
     msg.msg = "手机号格式不正确";

  }else{

    执行方法;

        }

posted @ 2018-12-26 20:40  up-zyn  阅读(3725)  评论(0)    收藏  举报