Integrate libphonenumber-for-php into popular PHP frameworks
libphonenumber-for-php can be integrated into various PHP frameworks through third-party packages. These packages provide framework-specific features like validation rules, form helpers, and service providers.
PhoneNumberBundleOfficial Symfony bundle for phone number handling
Laravel
Laravel PhoneComprehensive Laravel package with validation rules
TYPO3
TYPO3 Phone ExtensionPhone number handling for TYPO3 CMS
These packages are maintained by third parties. While they provide excellent integration capabilities, their quality and maintenance status may vary. Always check the package’s documentation and recent activity before integrating.
If your framework isn’t listed above, you can create a custom integration:
use libphonenumber\PhoneNumberUtil;use libphonenumber\PhoneNumberFormat;class PhoneNumberService{ private PhoneNumberUtil $phoneUtil; public function __construct() { $this->phoneUtil = PhoneNumberUtil::getInstance(); } public function format(string $number, string $region): string { try { $phoneNumber = $this->phoneUtil->parse($number, $region); return $this->phoneUtil->format( $phoneNumber, PhoneNumberFormat::INTERNATIONAL ); } catch (\Exception $e) { return $number; } } public function validate(string $number, string $region): bool { try { $phoneNumber = $this->phoneUtil->parse($number, $region); return $this->phoneUtil->isValidNumber($phoneNumber); } catch (\Exception $e) { return false; } }}
When creating custom integrations, always use the singleton pattern with getInstance() to ensure optimal performance. See the Performance page for more details.