PHPackages                             devsarfo/laraphone - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. devsarfo/laraphone

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

devsarfo/laraphone
==================

Laravel Phone Number Package based on the PHP port of libphonenumber by Google

v1.1(9mo ago)41.8kMITPHPPHP ^8.1CI passing

Since Apr 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/devsarfo/laraphone)[ Packagist](https://packagist.org/packages/devsarfo/laraphone)[ Docs](https://github.com/devsarfo/laraphone)[ GitHub Sponsors](https://github.com/DevSarfo)[ RSS](/packages/devsarfo-laraphone/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (6)Used By (0)

LaraPhone
=========

[](#laraphone)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7c62069fbde97169403753796e4f7dd7ef5d7b98866db6772b6513ab0f6bf3b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576736172666f2f6c61726170686f6e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devsarfo/laraphone)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b7fb61158bfe9c7e1b6bea15ec2be210ccf70670c66d3d887c8d8c3e0971b885/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646576736172666f2f6c61726170686f6e652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/devsarfo/laraphone/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/53a5a6d1f2d6f204ba81360a53b3fff83ac251e597f4aad8d03babcd458ed310/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646576736172666f2f6c61726170686f6e652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/devsarfo/laraphone/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/dbe27586a7234d04aff1d5428880921f84aac386ae7c7d6162341f4346f00c5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576736172666f2f6c61726170686f6e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devsarfo/laraphone)

Laravel Phone Number Package based on the [libphonenumber for PHP (Lite)](https://github.com/giggsey/libphonenumber-for-php-lite). It is a simple Laravel package for validating, formatting, and parsing phone numbers based on the PHP port of Google’s libphonenumber library, providing robust support for international phone number handling.

Installation
------------

[](#installation)

You can install the package via composer using the following command. The command will install the latest applicable version of the package.

```
composer require devsarfo/laraphone
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laraphone-config"
```

Optionally, you can publish the translations with :

```
php artisan vendor:publish --tag="laraphone-translations"
```

Usage
-----

[](#usage)

Use the `phone` keyword in your validation rules array or use the `DevSarfo\LaraPhone\Rules\PhoneNumberRule` rule class to define the rule in an expressive way.

To put constraints on the allowed originating countries, you can explicitly specify the allowed country codes.

```
'phone' => 'phone:NO,GH',
// 'phone' => new PhoneNumberRule(['NO', 'GH'])
```

You can pass the country code from another field in the request. For example, to require a phone number to match the user's country.

```
'country_code' => 'required',
'phone' => ['required', new PhoneNumberRule($this->country_code)],
```

The country codes should be [*ISO 3166-1 alpha-2 compliant*](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).

### Validation Message

[](#validation-message)

We provide validation for various cases out of the box. However, to enable the custom phone validation message, please add the following line to the `validation.php` language file in your `resources/lang/{language}/` directory (e.g., `resources/lang/en/validation.php`):

```
'phone' => 'The :attribute field must be a valid phone number.',
```

PhoneNumber Utility class
-------------------------

[](#phonenumber-utility-class)

You can use the `DevSarfo\LaraPhone\Models\PhoneNumber` class to handle various phone number operations, such as formatting, validating, and manipulating phone numbers. It provides an easy-to-use interface for working with phone numbers in different formats, and can be safely referenced in views or when saving to the database.

```
use DevSarfo\LaraPhone\Models\PhoneNumber;

(string) new PhoneNumber('+4722334455');    // +4722334455
(string) new PhoneNumber('22334455', 'NO'); // +4722334455
```

Alternatively you can use the `phone()` function found in the `Helper.php`. It returns a `DevSarfo\LaraPhone\Models\PhoneNumber` instance or the formatted string if `$format` was provided:

```
phone('+233244123456');             // PhoneNumber instance
phone('0244123456', 'GH');          // PhoneNumber instance
phone('0244123456', 'GH', $format); // string
```

### Formatting

[](#formatting)

A PhoneNumber can be formatted in various ways:

```
$phone = new PhoneNumber('0244123456', 'GH');

$phone->format($format);       // See libphonenumber\PhoneNumberFormat
$phone->formatE164();          // +233244123456
$phone->formatInternational(); // +233 24 412 3456
$phone->formatRFC3966();       // tel:+233-24-412-3456
$phone->formatNational();      // 024 412 3456
```

### Database

[](#database)

Store phone numbers in the **E.164** format in your database. This format globally uniquely identifies a phone number, ensuring consistency and simplifying validation.

For example:

- **User input**: `0244123456` (GH number)
- **Database storage**: `+233244123456`

### Why E.164 Format?

[](#why-e164-format)

- **Consistency**: E.164 format uniquely identifies a phone number globally.
- **Flexibility**: You can format the number for display purposes (e.g., national or international formats).

### Example Workflow:

[](#example-workflow)

1. **User Input**: `0244123456`
2. **Format to E.164**: `+233244123456`
3. **Save in Database**: Store as `+233244123456`
4. **Display**: Format it as needed, e.g., `0244 123 456` for Ghana.

This ensures unique, globally recognizable phone numbers that can be displayed differently based on user needs.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Bernard Sarfo Twumasi](https://github.com/devsarfo)
- [Joshua Gigg - libphonenumber for PHP (Lite)](https://github.com/giggsey/libphonenumber-for-php-lite)
- [Google - libphonenumber](https://github.com/google/libphonenumber)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance75

Regular maintenance activity

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~105 days

Total

2

Last Release

298d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4427f1c6360881b26a4c99137175c96caf7ae61996e66d63c0229c7265f5ec43?d=identicon)[devsarfo](/maintainers/devsarfo)

---

Top Contributors

[![devsarfo](https://avatars.githubusercontent.com/u/20325487?v=4)](https://github.com/devsarfo "devsarfo (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

laravellaraphonedevsarfo

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/devsarfo-laraphone/health.svg)

```
[![Health](https://phpackages.com/badges/devsarfo-laraphone/health.svg)](https://phpackages.com/packages/devsarfo-laraphone)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ziming/laravel-zxcvbn

Zxcvbn Password validation rule for Laravel

3056.7k](/packages/ziming-laravel-zxcvbn)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
