package cn.iocoder.yudao.framework.common.validation;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IdCardValidator implements ConstraintValidator<IdCard, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {

        // 如果身份证为空，默认不校验，即校验通过
        if (StrUtil.isEmpty(value)) {
            return true;
        }

        // 检验身份证
        return ValidationUtils.isIdCard(value);
    }
}
