30 lines
692 B
PHP
30 lines
692 B
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace app\common\library;
|
||
|
||
/**
|
||
* 马来西亚手机号(60 国际前缀,不含 +)
|
||
*/
|
||
class MalaysiaMobilePhone
|
||
{
|
||
public const PATTERN = '/^60(1[0-9])\d{7,9}$/';
|
||
|
||
public static function isValid(string $phone): bool
|
||
{
|
||
return $phone !== '' && preg_match(self::PATTERN, $phone) === 1;
|
||
}
|
||
|
||
public static function maskInNickname(string $text): string
|
||
{
|
||
$masked = preg_replace_callback(
|
||
self::PATTERN,
|
||
static fn(array $matches): string => substr($matches[0], 0, 3) . '****' . substr($matches[0], -4),
|
||
$text
|
||
);
|
||
|
||
return is_string($masked) ? $masked : $text;
|
||
}
|
||
}
|