PHPackages                             laravelsn/phone-normalizer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. laravelsn/phone-normalizer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laravelsn/phone-normalizer
==========================

simple wayy to normalize phone number in laravel app

v1.0.0(6mo ago)0101MITPHPPHP ^8.3CI failing

Since Oct 25Pushed 6mo agoCompare

[ Source](https://github.com/Laravel-SN-Community/phone-normalizer)[ Packagist](https://packagist.org/packages/laravelsn/phone-normalizer)[ RSS](/packages/laravelsn-phone-normalizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

Phone Normalizer for Laravel
============================

[](#phone-normalizer-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7a3f1355503355a11024864d6748683bbfb035d6f520a4e940198e2007c30ce4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c736e2f70686f6e652d6e6f726d616c697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelsn/phone-normalizer)[![Total Downloads](https://camo.githubusercontent.com/1e4450e7984b83622442173633578f00e9a1331eff8bb3d86edfa445677b1d99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c736e2f70686f6e652d6e6f726d616c697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelsn/phone-normalizer)

A simple and efficient Laravel package to normalize phone numbers for various countries, with a focus on African nations.

Features
--------

[](#features)

- ✅ Normalize phone numbers to international format
- ✅ Validate phone number format and length
- ✅ Support for multiple countries (Senegal, Côte d'Ivoire, and more)
- ✅ Easy to extend with new countries
- ✅ Configurable default country
- ✅ Laravel auto-discovery support

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

[](#installation)

Install the package via Composer:

```
composer require laravelsn/phone-normalizer
```

The service provider will be automatically registered.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

If you want to customize the configuration:

```
php artisan vendor:publish --tag=phonenormalizer-config
```

This will create a `config/phonenormalizer.php` file where you can customize settings.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Laravelsn\PhoneNormalizer\Facades\PhoneNormalizer as Phone;

// Normalize a Senegalese phone number
$normalized = Phone::normalize('78 123 45 67');
// Returns: +221781234567

// Normalize with spaces or special characters
$normalized = Phone::normalize('78-123-45-67');
// Returns: +221781234567
```

### Specify Country Code

[](#specify-country-code)

```
// Normalize a phone number from Côte d'Ivoire
$normalized = Phone::normalize('0123456789', 'CI');
// Returns: +2250123456789

// Senegal (default)
$normalized = Phone::normalize('771234567', 'SN');
// Returns: +221771234567
```

### Validation

[](#validation)

The `normalize()` method returns `null` if the phone number is invalid:

```
$normalized = Phone::normalize('123'); // Invalid number
// Returns: null

if ($normalized === null) {
    // Handle invalid phone number
}
```

Configuration
-------------

[](#configuration)

After publishing the configuration file, you can customize the default country and add new countries:

```
// config/phonenormalizer.php

return [
    'default_country' => env('PHONE_NORMALIZER_DEFAULT_COUNTRY', 'SN'),

    'countries' => [
        'SN' => [
            'code' => '+221',
            'pattern' => '/^(7[05678][0-9]{7})$/',
            'length' => 9,
        ],
        'CI' => [
            'code' => '+225',
            'pattern' => '/^(0[157]|2[57])[0-9]{8}$/',
            'length' => 10,
        ],
        // Add more countries here
    ],
];
```

### Environment Variables

[](#environment-variables)

Set the default country in your `.env` file:

```
PHONE_NORMALIZER_DEFAULT_COUNTRY=SN
```

Supported Countries
-------------------

[](#supported-countries)

CountryCodeFormatExampleSenegalSN9 digits771234567 → +221771234567Côte d'IvoireCI10 digits0123456789 → +2250123456789Want to add more countries? See the [Contributing](#contributing) section!

Adding New Countries
--------------------

[](#adding-new-countries)

You can add new countries by publishing the configuration and adding them to the `countries` array:

```
'countries' => [
    'ML' => [ // Mali
        'code' => '+223',
        'pattern' => '/^[0-9]{8}$/',
        'length' => 8,
    ],
    // ... other countries
],
```

Use Cases
---------

[](#use-cases)

- **User Registration**: Normalize phone numbers during registration
- **SMS Sending**: Ensure phone numbers are in the correct format before sending SMS
- **Database Storage**: Store phone numbers in a consistent format
- **API Integration**: Normalize phone numbers before sending to external APIs

Example in Controller
---------------------

[](#example-in-controller)

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Laravelsn\PhoneNormalizer\Facades\PhoneNormalizer as Phone;

class UserController extends Controller
{
    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|string',
            'phone' => 'required|string',
        ]);

        $normalizedPhone = Phone::normalize($validated['phone']);

        if ($normalizedPhone === null) {
            return back()->withErrors([
                'phone' => 'Invalid phone number format'
            ]);
        }

        User::create([
            'name' => $validated['name'],
            'phone' => $normalizedPhone,
        ]);

        return redirect()->route('users.index');
    }
}
```

Testing
-------

[](#testing)

Run the tests with:

```
composer test
```

Or using Pest directly:

```
./vendor/bin/pest
```

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 11.0 or 12.0

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

### How to Contribute

[](#how-to-contribute)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Adding New Countries

[](#adding-new-countries-1)

We especially welcome contributions to add support for new countries! Just add the country configuration following the existing pattern.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [LaravelSn](https://github.com/laravelsn)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Changelog
---------

[](#changelog)

### 1.0.0 - 2025-10-26

[](#100---2025-10-26)

- Initial release
- Support for Senegal (SN)
- Support for Côte d'Ivoire (CI)
- Phone number validation
- Phone number normalization to international format

Support
-------

[](#support)

If you find this package helpful, please consider:

- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 📖 Improving documentation

---

Made with ❤️ by [LaravelSn](https://github.com/laravelsn)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance67

Regular maintenance activity

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

205d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd5ded86d76c5b718c9880c799facb0d74012060d29c40b227cb4cb91a549c0d?d=identicon)[Kepsondiaz](/maintainers/Kepsondiaz)

---

Top Contributors

[![Kepsondiaz](https://avatars.githubusercontent.com/u/67605105?v=4)](https://github.com/Kepsondiaz "Kepsondiaz (16 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/laravelsn-phone-normalizer/health.svg)

```
[![Health](https://phpackages.com/badges/laravelsn-phone-normalizer/health.svg)](https://phpackages.com/packages/laravelsn-phone-normalizer)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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