All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.chobit.commons.validation.ChineseOnlyValidator Maven / Gradle / Ivy

There is a newer version: 0.1.3.4
Show newest version
package org.chobit.commons.validation;


import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.chobit.commons.utils.CharacterChecker;

import static org.chobit.commons.utils.StrKit.isBlank;

/**
 * @author robin
 */
public class ChineseOnlyValidator implements ConstraintValidator {


    private boolean allowPunctuation;

    @Override
    public void initialize(ChineseOnly annotation) {
        this.allowPunctuation = annotation.allowPunctuation();
    }

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

        if (isBlank(value)) {
            return true;
        }

        return CharacterChecker.isChineseOnly(value, this.allowPunctuation);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy