/**
* 验证电话号码
*/
private static Pattern pattern = Pattern.compile("0\\d{2,3}[-]?\\d{7,8}|0\\d{2,3}\\s?\\d{7,8}|[1-9]\\d{6,7}");
/**
* 校验电话号码格式,校验异常返回空
*
* @param officePhone
* 办公电话
* @return 校验结果
*/
private static String validOfficePhonePattern(String officePhone) {
if (StringUtils.isBlank(officePhone)) {
return officePhone;
} else {
String newStr = StringUtils.replace(officePhone, "--", "-").replaceAll("——", "-");
Matcher matcher = pattern.matcher(newStr);
boolean bool = matcher.matches();
if (bool) {
return newStr;
} else {
return StringUtils.EMPTY;
}
}
}
来源:oschina
链接:https://my.oschina.net/u/4170983/blog/3184987