PHPackages                             aklump/phone-number - 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. aklump/phone-number

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

aklump/phone-number
===================

A lean, non-dependency PHP library to work with phone numbers.

0.0.10(1mo ago)036BSD-3-ClausePHPPHP &gt;=7.4

Since Aug 14Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/aklump/phone-number)[ Packagist](https://packagist.org/packages/aklump/phone-number)[ Docs](https://github.com/aklump/phone-number)[ Fund](https://www.buymeacoffee.com/aklump)[ Fund](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4E5KZHDQCEUV8&item_name=Open%20Source%20Sponsorship)[ RSS](/packages/aklump-phone-number/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (4)Versions (11)Used By (0)

Phone Number
============

[](#phone-number)

A lean, non-dependency PHP library to work with phone numbers. The focus of the library is on U.S. phone numbers only at this time. To work with international phone numbers you might try [Phone Normalizer](https://github.com/aklump/phone-number), from which we've taken the same formatting strategy. (Thank you, [dmamontov](https://github.com/dmamontov) and [1on](https://github.com/1on).)

[![aklump/phone-number](images/aklump_phone_number.jpg)](images/aklump_phone_number.jpg)

Install with Composer
---------------------

[](#install-with-composer)

2. Require the latest stable version:

    ```
    composer require aklump/phone-number:^0.0
    ```
3. ... or require the dev channel:

    ```
    composer config minimum-stability dev
    composer require aklump/phone-number:@dev
    ```

Usage
-----

[](#usage)

### Formatting Numbers

[](#formatting-numbers)

- Tokens are:
    - `#CC#` for the country code.
    - `#c#` for the area code
    - `###` (leftmost three) for the local exchange.
    - `####` (rightmost four) for subscriber number.
- Pre-defined formats provided by `\AKlump\PhoneNumber\PhoneNumberFormats`
- Invalid phone numbers will not format, but throw an exception.
- To obtain a list of violations for an invalid phone number use the `::validate` method.

```
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter();
$number = $phone->format('3608881223');
// '(360) 888-1223' === $formatted
```

If the context of your app is regional, you maybe want to assume a default area code.

```
$default_area_code = 360;
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter($default_area_code);

$number = $phone->format('8881223');
// '(360) 888-1223' === $formatted
```

#### Formatted for SMS

[](#formatted-for-sms)

```
$number = $phone->format('888-1223', \AKlump\PhoneNumber\PhoneNumberFormats::SMS);
// '+13608881223' === $number
```

#### Using Custom Formats

[](#using-custom-formats)

```
// Provide a custom default format.
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter(360, '+#CC#.#c#.###.####');
$number = $phone->format('888-1223');
// '+1.360.888.1223' === $number
```

#### Outside the Box Thinking

[](#outside-the-box-thinking)

```
// Convert to a JSON string.
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter(360, \AKlump\PhoneNumber\PhoneNumberFormats::JSON);
$number = $phone->format('888-1223');
// '{"country":"+1","areaCode":206,"localExchange":555,"subscriberNumber":1212}' === $number
```

### Validating Numbers

[](#validating-numbers)

```
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter();
$violations = $phone->validate('3608881223');
foreach($violations as $violation) {
  echo $violation;
}
$is_valid = empty($violations);
```

- See also `\AKlump\PhoneNumber\PhoneNumberViolations`

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance94

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

Every ~78 days

Recently: every ~175 days

Total

10

Last Release

31d ago

PHP version history (2 changes)0.0.1PHP &gt;=7.3

0.0.10PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/79476f3b82f9c766433c7eb401cbcfc636cd5d5ccf2b2e6b50ea81d1de6c2730?d=identicon)[aklump](/maintainers/aklump)

---

Top Contributors

[![aklump](https://avatars.githubusercontent.com/u/425737?v=4)](https://github.com/aklump "aklump (45 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aklump-phone-number/health.svg)

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

PHPackages © 2026

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