love.keeping.starter.web.components.validation.CodeValidator Maven / Gradle / Ivy
The newest version!
package love.keeping.starter.web.components.validation;
import love.keeping.starter.common.constants.PatternPool;
import love.keeping.starter.common.utils.RegUtil;
import love.keeping.starter.common.utils.StringUtil;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* 编号校验 如果参数是null或empty 则通过校验
*
* @author Keeping
*/
public class CodeValidator implements ConstraintValidator {
@Override
public boolean isValid(CharSequence charSequence,
ConstraintValidatorContext constraintValidatorContext) {
return StringUtil.isEmpty(charSequence) || RegUtil.isMatch(PatternPool.PATTERN_CODE,
charSequence.toString());
}
}