feat(profile): enhance national_code uniqueness error message with masked mobile number
This commit is contained in:
@@ -13,25 +13,25 @@ final class InputValidator
|
||||
return (bool) preg_match('/^09\d{9}$/', self::toEnglishDigits($mobile));
|
||||
}
|
||||
|
||||
/** کد ملی ایران: ۱۰ رقم + الگوریتم رقم کنترلی؛ ارقام یکسان نامعتبر. */
|
||||
/** کد ملی: فقط باید دقیقاً ۱۰ رقم باشد (بدون بررسی رقم کنترلی). */
|
||||
public static function isValidIranNationalCode(string $code): bool
|
||||
{
|
||||
$code = self::toEnglishDigits($code);
|
||||
if (!preg_match('/^\d{10}$/', $code)) {
|
||||
return false;
|
||||
}
|
||||
if (preg_match('/^(\d)\1{9}$/', $code)) {
|
||||
return false;
|
||||
}
|
||||
return (bool) preg_match('/^\d{10}$/', self::toEnglishDigits($code));
|
||||
}
|
||||
|
||||
$check = (int) $code[9];
|
||||
$sum = 0;
|
||||
for ($i = 0; $i < 9; $i++) {
|
||||
$sum += (int) $code[$i] * (10 - $i);
|
||||
/**
|
||||
* موبایل را برای نمایش ماسک میکند: 09120675433 → 0912****33 (۴ رقم اول + ۲ رقم آخر).
|
||||
* نتیجه با Unicode LTR-isolate (U+2066…U+2069) محصور میشود تا داخلِ متنِ فارسیِ RTL
|
||||
* جهتِ ارقام/ستاره بههم نریزد.
|
||||
*/
|
||||
public static function maskMobile(string $mobile): string
|
||||
{
|
||||
$mobile = self::toEnglishDigits($mobile);
|
||||
if (strlen($mobile) < 6) {
|
||||
return $mobile;
|
||||
}
|
||||
$r = $sum % 11;
|
||||
|
||||
return $r < 2 ? $check === $r : $check === 11 - $r;
|
||||
$masked = substr($mobile, 0, 4) . '****' . substr($mobile, -2);
|
||||
return "\u{2066}{$masked}\u{2069}";
|
||||
}
|
||||
|
||||
public static function toEnglishDigits(string $s): string
|
||||
|
||||
Reference in New Issue
Block a user