64 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Utils;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
/**
* 正则
*/
class PcreMatch
{
private static string $PregIdCard = '/^(?:1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5])\d{4}(?:1[89]|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dxX]$/';
/**
* 匹配身份证
* @param string $id_number
* @return string
*/
public static function pregIdCard(string $id_number): string
{
if(empty($id_number))
{
throw new BusinessException("身份证号为空",HttpEnumCode::HTTP_ERROR);
}
preg_match(self::$PregIdCard, $id_number,$match);
if(empty($match))
{
throw new BusinessException("身份证号错误", HttpEnumCode::HTTP_ERROR);
}
return $match[0];
}
/**
* 匹配身份证最后一位修改为大写x
* @param string $id_number
* @return string
*/
public static function pregIdCardX(string $id_number): string
{
if(empty($id_number))
{
throw new BusinessException("身份证号为空",HttpEnumCode::HTTP_ERROR);
}
return str_replace("x","X",$id_number);
}
/**
* 匹配去除oss网址
* @param string $path
* @return string
*/
public static function pregRemoveOssWebsite(string $path): string
{
if (empty($path)){
return $path;
}
return str_replace('https://' . config('alibaba.oss.bucket') . '.' .config('alibaba.oss.endpoint'),"",$path);
}
}