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 Lite

Libphonenumber For Php Lite Laravel Package

giggsey/libphonenumber-for-php-lite

A lightweight PHP library for parsing, formatting, storing, and validating international phone numbers, based on Google's libphonenumber. This lite version includes core phone number utilities and requires PHP 8.1+ with mbstring.

View on GitHub
Deep Wiki
Context7

libphonenumber for PHP (Lite) is a lightweight PHP port of Google's libphonenumber for parsing, formatting, storing, and validating international phone numbers. It ships only the core Phone Number Utils; for geolocation, carrier, and short-number data, use the full giggsey/libphonenumber-for-php package. Requires PHP 8.1+ and the mbstring extension, installed via Composer.

  • Parse and validate numbers against current metadata
  • Format as E.164, international, national, or RFC 3966
  • Identify number type (mobile, fixed-line, toll-free, VoIP)
  • Small footprint — core utilities only
  • Tracks Google's libphonenumber data releases
Frequently asked questions about Libphonenumber For Php Lite
How do I install giggsey/libphonenumber-for-php-lite in Laravel?
Install it with composer require giggsey/libphonenumber-for-php-lite. The package requires PHP 8.1 or newer and the mbstring extension. It is framework agnostic, so no Laravel service provider or config file is required; resolve PhoneNumberUtil::getInstance() where needed.
Can I use libphonenumber-for-php-lite with Laravel validation?
Yes. Create a custom Laravel validation rule that calls PhoneNumberUtil::getInstance()->parse() and then isValidNumber(). Catch NumberParseException and return false for unparseable input. For national-format input, pass the user's region code to parse(); for E.164 input beginning with +, a null region is typically fine.
How should I store international phone numbers in a Laravel database?
Normalize numbers to E.164 with PhoneNumberFormat::E164 before saving, for example +14155552671. Store the result in a string column and index it if you query by phone. You can do this in a model mutator, form request, or service layer so every write path uses the same normalization.
How do I format phone numbers for display in Laravel?
Parse the stored E.164 value and call format() with PhoneNumberFormat::NATIONAL or PhoneNumberFormat::INTERNATIONAL depending on context. Use E164 for APIs and storage, and a local or national format for user-facing pages when you know the country. Formatting does not replace validation, so validate before saving and formatting.
What is the difference between libphonenumber-for-php-lite and the full package?
The lite package includes the core phone number utilities for parsing, validating, and formatting. The full giggsey/libphonenumber-for-php package adds geolocation, carrier information, and short number info. Choose lite when you only need core number handling and want a smaller dependency.
Which Laravel and PHP versions are supported?
The lite package requires PHP 8.1 or newer and mbstring, and it is framework agnostic. It can be used in any Laravel version that runs on a supported PHP version, including modern Laravel 10, 11, and 12 applications. Composer will enforce the PHP requirement during installation.
Can I validate phone numbers from multiple countries?
Yes. For internationally formatted input beginning with +, parse() can infer the country. For local-format input, pass the correct ISO region code, such as US or GB, as the second argument to parse(). Then call isValidNumber() and optionally getNumberType() for extra context.
How should I handle invalid phone numbers with this package?
Catch NumberParseException for malformed input and treat isValidNumber() returning false as invalid. Decide whether your application should be strict and reject the value or lenient and preserve raw input separately. In most Laravel apps, return a validation error and avoid storing unvalidated numbers.
Is libphonenumber-for-php-lite fast enough for production Laravel apps?
For typical Laravel apps it is fast enough because it is pure PHP and avoids external services. The lite edition loads core phone metadata, so cache or reuse the PhoneNumberUtil instance rather than creating it repeatedly. If you process very high request volumes, benchmark parsing and formatting in your own environment.
How do I test phone number validation in Laravel, and how often should I update the package?
Write unit tests with known valid and invalid numbers for each region you support, and test your Laravel validation rule and model normalization paths. Because phone number rules come from Google's metadata, update the package with Composer periodically and rerun those tests after updates. If you see a disputed number, compare behavior with Google's libphonenumber demo and check package release notes.
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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc