package com.ruoyi.ext.api.validate;

import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * 自定义QQ校验注解实现
 * 
 * @author ruoyi
 */
public class QQValidator implements ConstraintValidator<QQV, String>
{
    String pattern;
    Pattern compile;

    @Override
    public void initialize(QQV constraintAnnotation) {
        pattern = "^[1-9]\\d{4,8}$";
        compile = Pattern.compile(pattern);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isBlank(value)){
            return true;
        }
        return compile.matcher(value).matches();
    }
}