package com.scm.contract.tools;

/**
 * @author zuo
 * @date 2024/7/23 13:31
 */

import java.util.regex.Pattern;

public class Validator {
    private static final String EMAIL_PATTERN =
            "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";

    private static final Pattern EMAIL_REGEX = Pattern.compile(EMAIL_PATTERN);

    public static boolean isEmailValid(String email) {
        if (email == null) {
            return false;
        }
        return EMAIL_REGEX.matcher(email).matches();
    }

    // 校验手机号码
    private static final Pattern MOBILE_PATTERN = Pattern.compile("^1[3-9]\\d{9}$");

    // 校验固定电话号码（示例，可能需要根据实际情况调整）
    private static final Pattern FIXED_LINE_PATTERN = Pattern.compile("^(0)\\d{2}-\\d{8}$|^(0)\\d{3}-\\d{7}$");

    /**
     * 验证电话号码是否有效
     * @param phoneNumber 要验证的电话号码
     * @return 如果电话号码有效则返回true，否则返回false
     */
    public static boolean isValidPhone(String phoneNumber) {
        if (MOBILE_PATTERN.matcher(phoneNumber).matches()) {
            return true;
        } else return FIXED_LINE_PATTERN.matcher(phoneNumber).matches();
    }
}
