1.验证手机号是否合法
private boolean isMobileNo(String mobileNo) throws Exception{
try {
if(StringUtils.isBlank(mobileNo)){
throw new BaseException("中外运会员认证参数的司机手机号不能为空!");
}
Pattern p = Pattern.compile("^13[0-9]{9}|(15[0-35-9]|18[0123456789]|14[57]|17[0-9])[0-9]{8}$");
Matcher m = p.matcher(mobileNo);
return m.matches();
} catch (BaseException e) {
throw e;
} catch (Exception e) {
throw e;
}
}
这里是判断该手机号是否是合法的手机号,其中正则部分可以根据需求来个性化修改,个人常用的正则表达式如下:
手机号:^13[0-9]{9}|(15[0-35-9]|18[0123456789]|14[57]|17[0-9])[0-9]{8}$
移动 ^134[0-8][0-9]{7}|(13[5-9]|15[012789]|18[2378]|147)[0-9]{8}$
联通 ^(13[012]|15[56]|18[56]|145)[0-9]{8}$
电信 ^(133|153|180|189|181)[0-9]{8}|1349[0-9]{7}$