Weave Code
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 Lite

Libphonenumber For Php Lite Laravel Package

giggsey/libphonenumber-for-php-lite

Lite PHP port of Google’s libphonenumber: parse, validate, format, and store international phone numbers. Includes core PhoneNumberUtils only (no geolocation/carrier/short number info). Requires PHP 8.1+ and mbstring; install via Composer.

View on GitHub
Deep Wiki
Context7

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

Frequently asked questions about Libphonenumber For Php Lite
How do I integrate this package into Laravel’s form validation?
Extend Laravel’s validation by creating a custom rule. Use `PhoneNumberUtil::getInstance()` to parse and validate numbers, then return `true` or `false` based on `isValidNumber()`. Example: `return $phoneUtil->isValidNumber($phoneUtil->parse($value, $region));`. This works seamlessly with Laravel’s `FormRequest` validation.
Will this work with Laravel’s Eloquent models for storing phone numbers?
Yes. Normalize phone numbers to E.164 format before storing, then use Eloquent accessors/mutators to parse and format them dynamically. Example: `protected $casts = ['phone_number' => 'phone_number:e164'];` ensures consistent storage and retrieval.
What’s the difference between this package and the full `giggsey/libphonenumber-for-php`?
This *lite* version focuses on core utilities like parsing, validation, and formatting. The full package includes geolocation, carrier info, and short-number support. Use this if you only need validation/formatting to save space and improve performance.
Does this package support Laravel’s dependency injection (DI) container?
Yes, but it’s stateless. Use `PhoneNumberUtil::getInstance()` directly or wrap it in a Laravel service class for DI. Example: `app()->bind(PhoneNumberService::class, fn() => new PhoneNumberService());` for cleaner integration.
How do I handle invalid phone numbers in production?
Catch `NumberParseException` during parsing and log errors. Prompt users to correct invalid inputs or store them as `null` in your database. For critical systems, implement fallback logic like default country assumptions or manual review.
What PHP versions and extensions are required?
This package requires **PHP 8.1+** and the **mbstring** extension. Check compatibility with your Laravel version (Laravel 9+ supports PHP 8.1). If `mbstring` isn’t enabled, enable it in `php.ini` or configure your hosting provider.
Can I use this for real-time phone number formatting (e.g., as users type)?
Yes, but the lite version lacks the `AsYouTypeFormatter`. For real-time formatting, use the full package or implement a client-side library (e.g., Google’s libphonenumber JS) alongside this for validation. Cache formatted results server-side for performance.
How do I test phone number validation across different regions?
Use `PhoneNumberUtil::getExampleNumberByType()` to generate test numbers for regions like US, UK, or India. Write PHPUnit tests with assertions like `assertTrue($phoneUtil->isValidNumber($number))`. Include edge cases like toll-free or VoIP numbers.
Is this package thread-safe for Laravel’s request lifecycle?
Yes, the singleton `PhoneNumberUtil` is stateless and safe for Laravel’s single-threaded request lifecycle. Avoid multi-threading (e.g., queues) unless you synchronize access, as concurrent modifications could cause issues in rare edge cases.
How do I migrate from ad-hoc phone validation to this package?
Replace custom regex or validation logic with `isValidNumber()`. Start by validating new inputs, then update existing records to normalize them in E.164 format. Use Laravel migrations to add columns or alter data types as needed.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope