| | |
| | | } |
| | | return 0.0; |
| | | } |
| | | |
| | | public static function sanitizePhone(string|int $value, array $config = []):string |
| | | { |
| | | $digits = preg_replace('/\D/', '', (string) $value); |
| | | |
| | | $length = strlen($digits); |
| | | |
| | | if ($length < 10 || $length > 13) { // 13 = 3-digit country code + 10 |
| | | return ''; |
| | | } |
| | | |
| | | $countryCode = $length > 10 ? substr($digits, 0, $length - 10) : null; |
| | | $number = substr($digits, -10); |
| | | |
| | | $formatted = preg_replace('/(\d{3})(\d{3})(\d{4})/', '$1-$2-$3', $number); |
| | | |
| | | return $countryCode ? '+' . $countryCode . '-' . $formatted : $formatted; |
| | | } |
| | | } |