在实际开发中我们需要对手机号格式校验,以下是对中国手机号校验的实现。
public class PhoneUtils {
/**
* 中国手机号码
*/
private static Pattern CHINESE_PHONE_PATTERN = Pattern.compile("((13|15|17|18)\\d{9})|(14[57]\\d{8})");
/**
* 是否是有效的中国手机号码
* @param phone
* @return
*/
public static boolean isValidChinesePhone(String phone) {
if (phone == null || phone.length() != 11) {
return false;
}
Matcher matcher = CHINESE_PHONE_PATTERN.matcher(phone);
return matcher.matches();
}
/**
* 检查手机是否无效
* @param phone
* @return
*/
public static boolean isNotValidChinesePhone(String phone) {
return !isValidChinesePhone(phone);
}
/**
* 手机中间添加星号
* @param phone
* @param b