PHPackages                             erichowey/nanp-number-formatter - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. erichowey/nanp-number-formatter

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

erichowey/nanp-number-formatter
===============================

Take a NANP phone number and return it in a variety of formats.

2.0.0(4y ago)23.8kMITPHPPHP ^7.4 || ^8.0

Since Jun 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/erichowey/nanp-number-formatter)[ Packagist](https://packagist.org/packages/erichowey/nanp-number-formatter)[ Docs](https://github.com/erichowey/nanp-number-formatter)[ RSS](/packages/erichowey-nanp-number-formatter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (9)Used By (0)

Format a NANP Phone Number
==========================

[](#format-a-nanp-phone-number)

This utility takes a NANP (North American Numbering Plan) phone number, parses it and returns the number in a variety of formats.

Install
-------

[](#install)

You can install this package via composer

```
composer require erichowey/nanp-number-formatter

```

Supported Input Formats and Characters
--------------------------------------

[](#supported-input-formats-and-characters)

- 10 Digit `2125550123`
- 11 Digit `12125550123`
- E.164 `+12125550123`
- Parenthesis `(212) 555-0123`
- Dot `212.555.0123`
- Hyphen `212-555-0123`
- Space `212 555 0123`
- Letters `1800FLOWERS`

etc...

Outputted Formats
-----------------

[](#outputted-formats)

- E.164 `+12125550123`
- Dot Format `212.555.0123`
- Hyphen Format `212-555-0123`
- National Format `(212) 555-0123`
- National Format Plus One `1 (212) 555-0123`
- International Format `+1 212 555 0123`
- 10 Digit `2125550123`
- 11 Digit `12325550123`
- URI `tel:+12125550123`
- NPA `212`
- NXX `555`
- Line `0123`

Example Usage
-------------

[](#example-usage)

```
use Erichowey\NanpNumberFormatter\NanpNumberFormatter;
...
$number = NanpNumberFormatter::format("(212) 555-0123");

echo $number->e164; // +12125550123
echo $number->nationalFormat; // (212) 555-0123
echo $number->nationalFormatPlusOne; // 1 (212) 555-0123
echo $number->internationalFormat; // +1 212 555 0123
echo $number->dotFormat; // 212.555.0123
echo $number->hyphenFormat; // 212-555-0123
echo $number->tendigit; // 2125550123
echo $number->elevendigit; // 12125550123
echo $number->uri; // tel:+12125550123
echo $number->npa; // 212
echo $number->nxx; // 555
echo $number->line; // 0123
...
```

Wildcards
---------

[](#wildcards)

Historically, NANP telephone number wildcards have been represented with the following characters: `X` for 0-9, `N`for 2-9 and occasionally `Y` for 1-9 in dialplan matching. Since this tool accepts letter input, these wildcard characters cannot be used. To utilize wildcard characters, set the second parameter of the `format()` method to `true`. Use `*` to represent a wildcard character.

```
$number = NanpNumberFormatter::format("(212) 555-****", true);
```

Errors
------

[](#errors)

If an invalid or non nanp number is attempted to be formatted, a `NanpNumberFormatterException` will be thrown. They can be handled with the typical try/catch pattern:

```
try {
    $number = NanpNumberFormatter::format("1234");
} catch (NanpNumberFormatterException $e) {
    echo $e->getMessage(); // 1234 is less than 10 characters
}
```

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

[](#contributing)

Contributions are welcome. Criticism is even more welcome. You're welcome to submit a PR or open an issue. Please conform to PSR-12 standards and create tests for your PR.

Testing
-------

[](#testing)

Run

```
./vendor/bin/phpunit

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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 ~82 days

Recently: every ~120 days

Total

7

Last Release

1673d ago

Major Versions

0.0.1 → 1.0.02020-06-07

1.3.0 → 2.0.02021-10-12

PHP version history (3 changes)0.0.1PHP ^7.2

1.2.0PHP ^7.2 || ^8.0

2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![erichowey](https://avatars.githubusercontent.com/u/4033313?v=4)](https://github.com/erichowey "erichowey (20 commits)")

---

Tags

formatternanpnanpaparserphone-numberformatterphoneformatnumbernanp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/erichowey-nanp-number-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/erichowey-nanp-number-formatter/health.svg)](https://phpackages.com/packages/erichowey-nanp-number-formatter)
```

###  Alternatives

[ergebnis/json-printer

Provides a JSON printer, allowing for flexible indentation.

9138.2M24](/packages/ergebnis-json-printer)[dragon-code/codestyler

A tool to automatically fix Coding Style Standards issues by The Dragon Code.

291.8M16](/packages/dragon-code-codestyler)[hallindavid/manny

a package of manipulators that hopefully come in useful for those of us who always forget regex when we need it (manny is short for manipulation)

38103.3k2](/packages/hallindavid-manny)[helgesverre/toon

Token-Oriented Object Notation - A compact data format for reducing token consumption when sending structured data to LLMs

11841.4k9](/packages/helgesverre-toon)[kdn/yii2-json-editor

JSON editor widget (josdejong/jsoneditor) for Yii 2.

22570.0k3](/packages/kdn-yii2-json-editor)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

44127.5k6](/packages/jstewmc-rtf)

PHPackages © 2026

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