feat(helper): membuat helper untuk format nomor telepon
This commit is contained in:
parent
3c830259d8
commit
091f34b89b
@ -72,3 +72,20 @@ function sanitizeIntegers(array $data, array $integerKeys = []): array
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('formatPhoneNumber')) {
|
||||||
|
function formatPhoneNumber(string $number, string $prefix = '+62', bool $useDash = false): string
|
||||||
|
{
|
||||||
|
$clean = preg_replace('/\D+/', '', $number);
|
||||||
|
|
||||||
|
$clean = preg_replace('/^(0|62)/', '', $clean);
|
||||||
|
|
||||||
|
$formatted = $prefix.$clean;
|
||||||
|
|
||||||
|
if ($useDash) {
|
||||||
|
$formatted = preg_replace('/(\d{3})(\d{3,4})(\d{3,4})(\d+)?/', $prefix.'-$1-$2-$3$4', $formatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $formatted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user