{{-- Formats and link a telephone number --}}
@if (!empty($number))
-
@php
- $number = preg_replace('/\D/', '', $number); // Strip everything except digits
- $number=preg_replace('/^00/','+',$number);
-
-
- // When a country code is present, add this to the start of the link and trim leading zero
- if(strpos($number,'+')===0){
-
+ $number = preg_replace('/[^\+0-9]/', '', $number); // Strip everything except digits and +
+ $number = preg_replace('/^00/','+',$number);
+ if(strpos($number,'+') === 0){
+ // If a leading + is present, the number is already at the right format
}elseif (isset($countryCode)) {
+ // When a country code is present, add this to the start of the link and trim leading zero
$number = "+{$countryCode}" . ltrim($number, 0);
}
@endphp
data-ga-label="phone" class="{{ $class ?? '' }}" href="tel:{{ $number }}">
{{ $slot }}
</a>
-
@endif