package com.kxs.common.core.util;





import com.kxs.common.core.exception.GlobalCustomerException;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 断言参数异常 util
 *
 * @author 没秃顶的码农
 * @date 2024-04-10
 */
public class AssertUtil {

     //手机的正则表达式
     private static final Pattern CHINA_PATTERN_PHONE = Pattern.compile("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");

    private static final Pattern YYYY_MM = Pattern.compile("^\\d{4}-(0[1-9]|1[0-2])$");

    public static final String CHINA_PATTERN_PHONE_STR =  "^((13[0-9])|(14[014-9])|(15[0-35-9])|(16[2567])|(17[0-8])|(18[0-9])|(19[0-35-9]))\\d{8}$";

     /**--------------------------------------------------------
     手机号断言
     --------------------------------------------------------**/
    public static void isPhone(String phone){

        //格式校验
        Matcher m = CHINA_PATTERN_PHONE.matcher(phone);
        if(!m.matches()){
            throw new GlobalCustomerException("手机号格式错误");
        }
    }
    /**--------------------------------------------------------
     时间格式断言
     --------------------------------------------------------**/
    public static void isYyyyMM(String month){

        //格式校验
        Matcher m = YYYY_MM.matcher(month);
        if(!m.matches()){
            throw new GlobalCustomerException("时间格式错误yyyy-MM");
        }
    }



}
