PHPackages                             syluxso/php-phone-format - 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. syluxso/php-phone-format

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

syluxso/php-phone-format
========================

Clean, validate, and format any US based phone format

v1.0.2(1y ago)054MITPHP

Since Jan 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Syluxso/PhpPhoneFormat)[ Packagist](https://packagist.org/packages/syluxso/php-phone-format)[ RSS](/packages/syluxso-php-phone-format/feed)WikiDiscussions main Synced 1mo ago

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

PhpPhoneFormat
==============

[](#phpphoneformat)

VERSION release/1.0.0 (current)
-------------------------------

[](#version-release100-current)

GOAL
----

[](#goal)

The goals of this library are:

- Clean a string and make it a valid phone number if possible.
- Format valid phone numbers into many display formats automatically.
- Provide true/false for if the string is a valid phone number.
- Break the phone into an array
- Remove preceeding "+" and/or "1". They will be added back in again if the phone is valid.

This library is designed for use with USA phone formatting only.

What this class does
--------------------

[](#what-this-class-does)

- Take the string and remove all non int values.
- Remove preceding '1' digit.
- Split string into an array of only numeric string items.
- Validate true/false for if the phone is valid format.
- Format the phone number into a range of phone formats.
- Add error messages if needed.

#### Example: Valid 10 digit phone

[](#example-valid-10-digit-phone)

```
$phone = new PhoneFormat('5555555555');

// Object example
{
  $phone->clean: 5555555555
  $phone->string: "5555555555"
  $phone->dashes: "555-555-5555"
  $phone->brackets: "(555) 555-5555"
  $phone->brackets_alt: "(555) 555 - 5555"
  $phone->spaces: "555 555 5555"
  $phone->dots: "555.555.5555"
  $phone->with_code_plus: "+15555555555"
  $phone->with_code_no_plus: "15555555555"
  $phone->array: [
    0 => "5",
    1 => "5",
    2 => "5",
    3 => "5",
    4 => "5",
    5 => "5",
    6 => "5",
    7 => "5",
    8 => "5",
    9 => "5",
  ]
  $phone->error: false
  $phone->valid: true
}
```

#### Example: Valid 10 digit phone but starts with "+1", "+" or "1".

[](#example-valid-10-digit-phone-but-starts-with-1--or-1)

```
$phone = new PhoneFormat('+15555555555');

// Object example
{
  $phone->clean: 5555555555
  $phone->string: "5555555555"
  $phone->dashes: "555-555-5555"
  $phone->brackets: "(555) 555-5555"
  $phone->brackets_alt: "(555) 555 - 5555"
  $phone->spaces: "555 555 5555"
  $phone->dots: "555.555.5555"
  $phone->with_code_plus: "+15555555555"
  $phone->with_code_no_plus: "15555555555"
  $phone->array: [
    0 => "5",
    1 => "5",
    2 => "5",
    3 => "5",
    4 => "5",
    5 => "5",
    6 => "5",
    7 => "5",
    8 => "5",
    9 => "5",
  ]
  $phone->error: false
  $phone->valid: true
}
```

#### Example: Valid phone with formatting already in place.

[](#example-valid-phone-with-formatting-already-in-place)

```
$phone = new PhoneFormat('(555) 555-5555');

// Object example
{
  $phone->clean: 5555555555
  $phone->string: "5555555555"
  $phone->dashes: "555-555-5555"
  $phone->brackets: "(555) 555-5555"
  $phone->brackets_alt: "(555) 555 - 5555"
  $phone->spaces: "555 555 5555"
  $phone->dots: "555.555.5555"
  $phone->with_code_plus: "+15555555555"
  $phone->with_code_no_plus: "15555555555"
  $phone->array: [
    0 => "5",
    1 => "5",
    2 => "5",
    3 => "5",
    4 => "5",
    5 => "5",
    6 => "5",
    7 => "5",
    8 => "5",
    9 => "5",
  ]
  $phone->error: false
  $phone->valid: true
}
```

#### Example: Invalid phone number

[](#example-invalid-phone-number)

```
/*
 * Will also fail:
 * 555 too view digits
 * (55) 555-5555 too view digits.
 * +155544433 (too view digits once "+1" is stripped.
 */
$phone = new PhoneFormat('1444555666');

// Object example
{
  $phone->clean: null
  $phone->dashes: null
  $phone->brackets: null
  $phone->brackets_alt: null
  $phone->spaces: null
  $phone->dots: null
  $phone->with_code_plus: null
  $phone->with_code_no_plus: null
  $phone->string: "1444555666"
  $phone->array: [
    0 => "4"
    1 => "4"
    2 => "4"
    3 => "5"
    4 => "5"
    5 => "5"
    6 => "6"
    7 => "6"
    8 => "6"
  ]
  $phone->error: array:2 [
    0 => "Phone numbers must be 10 characters."
    1 => "Not a valid US phone number."
  ]
  $phone->valid: false
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance41

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

Every ~0 days

Total

2

Last Release

499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2285e4bc02c1132d05c9f7cd6b449cc39ff65b4a542578bb5f44a4e85eefa505?d=identicon)[Syluxso](/maintainers/Syluxso)

---

Top Contributors

[![Syluxso](https://avatars.githubusercontent.com/u/68607411?v=4)](https://github.com/Syluxso "Syluxso (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/syluxso-php-phone-format/health.svg)

```
[![Health](https://phpackages.com/badges/syluxso-php-phone-format/health.svg)](https://phpackages.com/packages/syluxso-php-phone-format)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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