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

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

baraja-core/phone-number
========================

Simple package for phone number manipulation.

v1.0.8(3y ago)6104.0k[1 issues](https://github.com/baraja-core/phone-number/issues)4PHPPHP ^8.0

Since Apr 21Pushed 3y ago2 watchersCompare

[ Source](https://github.com/baraja-core/phone-number)[ Packagist](https://packagist.org/packages/baraja-core/phone-number)[ Docs](https://github.com/baraja-core/phone-number)[ RSS](/packages/baraja-core-phone-number/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (7)Versions (12)Used By (4)

Validation and formatting of telephone numbers
==============================================

[](#validation-and-formatting-of-telephone-numbers)

[Read Czech version](https://php.baraja.cz/telefonni-cisla)

There is no easy way to validate and format phone numbers in PHP, so I wrote a simple library for this that has no dependencies, but still handles this role.

The goal is to check the format of a phone number, or convert it to a basic canonical form (which is always valid).

Installing
----------

[](#installing)

Simply composer:

```
$ composer require baraja-core/phone-number

```

How to use the library
----------------------

[](#how-to-use-the-library)

The principle of this tool is based on formatting and validating phone numbers from the user, or from sources over which you have no control.

The most common use is to correct phone number formatting:

```
$original = '+420 777123456';
$formatted = \Baraja\PhoneNumber\PhoneNumberFormatter::fix($original);

echo $original . '';
echo $formatted;
```

The function fixes the number formatting and returns the string `+420 777 123 456`.

If no prefix is specified by the user, the `+420` prefix is assumed. You can change the default preference with the second parameter:

```
// returns: +421 777 123 456
\Baraja\PhoneNumber\PhoneNumberFormatter::fix('+420 777123456', 421);
```

The phone code is overwritten only if the user does not enter it and it fails to be detected automatically.

Input and output formatting
---------------------------

[](#input-and-output-formatting)

The input string can look (almost) any way. The built-in algorithm can automatically remove non-valid characters (for example, some users write a note next to a phone number that will be removed automatically). So you don't have to worry about formatting the input at all, but the output will always be consistent.

The output always looks the same (it is normalized to the canonical format).

The general format is:

```
   +420 777 123 456
     | \_________/
  Prefix |
      National number

```

If you submit a non-valid input (or an input that cannot be automatically corrected), an exception will be thrown.

Error trapping
--------------

[](#error-trapping)

If the number cannot be safely normalized to a base form, or does not exist, throw an `\InvalidArgumentException` exception.

If you wish to convert the exception to a boolean, use the built-in asset validator:

```
\Baraja\PhoneNumber\PhoneNumberValidator::isValid('123'); // false
\Baraja\PhoneNumber\PhoneNumberValidator::isValid('777123456'); // true
\Baraja\PhoneNumber\PhoneNumberValidator::isValid('+420 777123456'); // true
\Baraja\PhoneNumber\PhoneNumberValidator::isValid('+420 777 123 456'); // true
\Baraja\PhoneNumber\PhoneNumberValidator::isValid('+420 77 712 34 56'); // true
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

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

Recently: every ~110 days

Total

9

Last Release

1320d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3382204?v=4)[baraja](/maintainers/baraja)[@baraja](https://github.com/baraja)

---

Top Contributors

[![janbarasek](https://avatars.githubusercontent.com/u/4738758?v=4)](https://github.com/janbarasek "janbarasek (26 commits)")

---

Tags

assertnumberphonephone-numbervalidator

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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