自定义注解
/**
 * 手机号校验
 */
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Constraint(validatedBy = {MobilePhoneValidator.class})
public @interface MobilePhoneValid {
    String message() default "手机格式异常";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};
}
校验规则
/**
 * @Description 手机校验
 */
@Slf4j
public class MobilePhoneValidator implements ConstraintValidator<MobilePhoneValid, String> {
    private static final int PHONE_LENGTH =11;
    private static final Pattern pattern = Pattern.compile("^[1]\\d{10}#34;);
    @Override
    public boolean isValid(String phone, ConstraintValidatorContext context) {
        if(StrUtil.isBlank(phone)){
            log.warn("MolbiePhoneValidator phone is blank, phone = {}", phone);
            return false;
        }
        if(phone.length() != PHONE_LENGTH){
            log.warn("MolbiePhoneValidator phone length valid fail, phone = {}", phone);
            return false;
        }
        if(!pattern.matcher(phone).matches()){
            log.warn("MolbiePhoneValidator phone pattern valid fail, phone = {}", phone);
            return false;
        }
        return true;
    }
}
使用
    /**
     *  账号
     */
    @MobilePhoneValid
    private String account;备注:利用@Constraint注解,大家可以举一反三。
