package com.zjrs.zwnw.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import com.zjrs.zwnw.annotation.NumVaild;

import java.util.regex.Pattern;

public class NumValidator implements ConstraintValidator<NumVaild, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null || "".equals(value)) {
            return true;
        }
        try{
            Pattern pattern = Pattern.compile("[0-9]*");
            return pattern.matcher(value).matches();
        }catch (Exception ex){
            return false;
        }
    }
}
