Installation:
composer require victorybiz/laravel-tel-input
npm install intl-tel-input --save
Publish assets and config:
php artisan vendor:publish --provider="VictoryBiz\TelInput\TelInputServiceProvider" --tag=config
npm run dev # or build if using Laravel Mix
First Use Case: Add the directive to a Blade form:
<x-tel-input name="phone" placeholder="Enter phone number" />
This renders a country-aware phone input with auto-formatting.
Livewire Integration: For Livewire 2/3, use the provided component:
<x-tel-input wire:model="phone" name="phone" />
resources/views/vendor/tel-input/ for default templates.config/tel-input.php for default country, utilsScript, and other settings.resources/js/tel-input.js for customization hooks.Basic Form Integration:
<form method="POST" action="/contact">
@csrf
<x-tel-input name="phone" required />
<button type="submit">Submit</button>
</form>
+1 (123) 456-7890).Livewire Data Binding:
// Livewire Component
public $phone = '';
// Blade
<x-tel-input wire:model="phone" name="phone" />
Country-Specific Logic:
<x-tel-input
name="phone"
default-country="us"
separate-dial-code
wire:model="phone"
/>
default-country: Pre-selects a country (e.g., us, gb).separate-dial-code: Shows dial code separately (e.g., +1 dropdown).Validation:
use VictoryBiz\TelInput\Rules\Phone;
$request->validate([
'phone' => ['required', new Phone],
]);
VictoryBiz\TelInput\Rules\Phone for server-side validation.resources/views/vendor/tel-input/.intl-tel-input with your app’s JS.lang to the directive (e.g., lang="es") for translated UI.hidden-input to store raw formatted data:
<x-tel-input name="phone" hidden-input="phone_raw" />
Missing JavaScript:
intl-tel-input is included in your JS bundle and utilsScript is set in config (e.g., https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js).Livewire 3 Compatibility:
wire:model may not sync properly if using older Livewire versions.wire:model.live for real-time updates.Validation Mismatch:
new Phone(['country' => 'us']) to specify validation rules per country.Country Codes Not Loading:
intl-tel-input CSS or JS.node_modules/intl-tel-input/build/css/intlTelInput.css is linked in your layout.intlTelInput errors in browser dev tools.utils.js and country data files load (e.g., https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/country-data.js).<input type="hidden" name="phone_raw" id="phone_raw">
<script>
document.getElementById('phone').addEventListener('countrychange', (e) => {
console.log('Formatted:', e.target.value);
console.log('Full number:', e.target.intlTelInput.getNumber());
});
</script>
Custom Countries:
Modify config/tel-input.php to include/exclude countries:
'countries' => ['us', 'gb', 'de'], // Default: all
Dynamic Configuration: Pass options dynamically via Blade:
<x-tel-input
name="phone"
:options="['onlyCountries' => ['us', 'ca'], 'geoIpLookup' => false]"
/>
Event Listeners: Attach JS events to the input:
document.addEventListener('DOMContentLoaded', () => {
const input = document.querySelector('#phone');
input.intlTelInput('on', 'countrychange', (e) => {
console.log('Country changed:', e.countryData.iso2);
});
});
Server-Side Parsing:
Use the VictoryBiz\TelInput\Phone helper to parse numbers:
use VictoryBiz\TelInput\Phone;
$phone = Phone::parse($request->phone, 'us'); // Returns normalized E.164 format
How can I help you explore Laravel packages today?