package com.zjrs.appcomm.validation;

import cn.hutool.core.util.StrUtil;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * 联系电话格式验证
 * @author Pettyfer
 */
public class TelPhoneValidator implements ConstraintValidator<TelPhone, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (StrUtil.isEmpty(value)) {
            return true;
        }
        return value.matches("^(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{7,14}$")||value.matches("^[1][3-9][0-9]{9}$");
    }
}
