Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Libphonenumber For Php

Libphonenumber For Php Laravel Package

giggsey/libphonenumber-for-php

A PHP port of Google's libphonenumber for parsing, formatting, storing, and validating international phone numbers, with geocoding, carrier, and timezone mapping.

View on GitHub
Deep Wiki
Context7

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

Frequently asked questions about Libphonenumber For Php
How do I install giggsey/libphonenumber-for-php in a Laravel application?
Install it with Composer using composer require giggsey/libphonenumber-for-php. The package is PSR-4 autoloaded, so Laravel can use it immediately, but the mbstring PHP extension is required. PHP versions 8.1 through 8.5 are supported, and no database or external API setup is needed for core parsing and validation.
Is giggsey/libphonenumber-for-php compatible with Laravel 10, 11 and 12?
The package is framework-agnostic, so it works with modern Laravel versions as long as your PHP version is supported. It is compatible with PHP 8.1 to 8.5, which aligns with Laravel 10 and newer applications. You can bind PhoneNumberUtil as a singleton in Laravel's service container or use a third-party bundle such as Laravel Phone.
How do I validate an international phone number in Laravel using libphonenumber?
Get a PhoneNumberUtil instance, parse the input with a default region, and call isValidNumber on the parsed object. Wrap parsing in a try/catch because strict parsing can throw NumberParseException for malformed input. You can package this logic as a custom Laravel validation rule so registration and profile forms reuse the same checks.
What is the difference between libphonenumber-for-php and libphonenumber-for-php-lite?
The lite package provides only the core PhoneNumberUtil features for parsing, formatting and validating numbers, making it smaller. The full giggsey/libphonenumber-for-php package adds geocoding, carrier mapping, timezone mapping and short-number information. Choose the full package when you need those advanced telecom lookups, or the lite version when core validation is enough.
How should I format and store phone numbers in a Laravel database?
Parse the number and format it as E.164 using PhoneNumberFormat::E164, then store the normalized value such as +14155552671. This avoids re-parsing and keeps searches and comparisons consistent. You may also keep the raw user input in a separate column if you need to display exactly what was entered.
Can I get carrier and timezone information from a phone number with this package?
Yes. The full package includes mappers for carrier names and timezones, such as PhoneNumberToCarrierMapper and PhoneNumberToTimeZonesMapper. These lookups work best with valid numbers and rely on Google libphonenumber metadata. Carrier names may depend on language tags, so handle fallback locales gracefully in your application.
How do I handle NumberParseException when users submit invalid phone numbers?
Strict parsing throws NumberParseException, so catch it wherever you parse untrusted input. For form validation, return false or a validation error rather than letting the exception break the request. If your business rules allow lenient parsing, use isValidNumber after parsing and handle failures per use case.
Does libphonenumber-for-php support short numbers such as emergency services?
The package includes ShortNumberInfo for short-number data such as emergency and toll-free codes. Short numbers and non-standard formats like VoIP can still require custom logic because behavior varies by region. Test these cases with real-world datasets rather than assuming standard validation covers them.
How do I register libphonenumber as a singleton in Laravel's service container?
In AppServiceProvider, bind libphonenumber\PhoneNumberUtil::class as a singleton that returns PhoneNumberUtil::getInstance(). That keeps one shared instance available through dependency injection. For high-throughput APIs, you can also cache parsed numbers in Redis or another cache layer to reduce repeated work.
How do I keep libphonenumber phone metadata up to date in a Laravel project?
Phone metadata comes from Google's libphonenumber releases, so update the Composer package regularly to get current data. Stale metadata can cause valid new numbers to fail validation, so add CI/CD checks or scheduled dependency updates. If you build metadata locally, automate the build step and include it in your deployment checks.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
kjmtrue/laravel-debugbar
hexincorp/debugbar
razorbacks/laravel-shibboleth
adilazhari/laravel-idempotency
mamitech/laravel-slow-query-log
mamitech/laravel-http-logger
medeirosrafael/docxmustache
webdevlabs/phreak
vis/log-envelope
digitickets/lalit
acacha/names
scool/foundation
frankkessler/guzzle-oauth2-middleware
delatbabel/site-config
delatbabel/applog
eusonlito/laravel-gettext
henzeb/housepedia-intelligence-laravel
aliqsm/laravel-authkit
itsjustvita/laravel-wp-migrator
uslanozan/laravel-cache-contract