package com.ruoyi.web.v2.v1.utils;

import java.util.regex.Pattern;

public class PhoneNumberValidator {

    public static boolean isValidPhoneNumber(String phoneNumber) {
        // 正则表达式用于验证手机号
        String pattern = "1[3456789]\\d{9}";

        // 判断输入的手机号是否符合规则
        return Pattern.matches(pattern, phoneNumber);
    }

    public static boolean isValidContact(String phoneNumber) {
        if (phoneNumber == null || phoneNumber.trim().isEmpty()) {
            return false;
        }

        // 移除空格
        String cleanedNumber = phoneNumber.trim();

        // 手机号正则
        String mobilePattern = "^(?:(?:13[0-9])|(?:14[0-57-9])|(?:15[0-3,5-9])|(?:16[2567])|(?:17[0-8])|(?:18[0-9])|(?:19[0-35-9]))\\d{8}$";

        // 座机号码正则
        String landlinePattern = "^0\\d{2,3}-\\d{7,8}(-\\d{1,6})?$";

        // 简单的座机号码（无分机）
        String simpleLandlinePattern = "^0\\d{2,3}-\\d{7,8}$";

        return Pattern.matches(mobilePattern, cleanedNumber) ||
                Pattern.matches(landlinePattern, cleanedNumber) ||
                Pattern.matches(simpleLandlinePattern, cleanedNumber);
    }

    public static void main(String[] args) {
        String phoneNumber = "手机号"; // 替换为要验证的手机号
        boolean isValid = isValidPhoneNumber(phoneNumber);
        if (isValid) {
            System.out.println("手机号正确！");
        } else {
            System.out.println("手机号错误！");
        }
    }
}

