PHPackages                             20steps/phone-number-bundle - 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. 20steps/phone-number-bundle

ActiveSymfony-bundle[Validation &amp; Sanitization](/categories/validation)

20steps/phone-number-bundle
===========================

Integrates libphonenumber into your Symfony2 application

v1.2.0(9y ago)070MITPHPPHP &gt;=5.3.3

Since Oct 10Pushed 9y ago4 watchersCompare

[ Source](https://github.com/20steps/phone-number-bundle)[ Packagist](https://packagist.org/packages/20steps/phone-number-bundle)[ Docs](https://github.com/misd-service-development/phone-number-bundle)[ RSS](/packages/20steps-phone-number-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (10)Versions (14)Used By (0)

PhoneNumberBundle
=================

[](#phonenumberbundle)

[![Build Status](https://camo.githubusercontent.com/aede1e97bbcc8e43b9706db2dfd5ab7f71b10d34427a2b2d62b2d5cb2bdc5683/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6973642d736572766963652d646576656c6f706d656e742f70686f6e652d6e756d6265722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/misd-service-development/phone-number-bundle)[![Total Downloads](https://camo.githubusercontent.com/bf00753f5074d94776fd614a82095663e56043b6054366ca4575c3fd585a1b2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6973642f70686f6e652d6e756d6265722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/misd/phone-number-bundle)[![Downloads per month](https://camo.githubusercontent.com/f9e7621afa2d9e674e36a985751e1909b347f783954b499df111c76109de517d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6973642f70686f6e652d6e756d6265722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/misd/phone-number-bundle)[![Latest stable version](https://camo.githubusercontent.com/9f099722cf95655ede7bdd5716db83e1fcd8145a449901c01db254079e9e5721/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6973642f70686f6e652d6e756d6265722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/misd/phone-number-bundle)[![License](https://camo.githubusercontent.com/b53222f72de1c6ec2ea9c5dee655839377cf7399b4068c1c974901af1e8ab8c2/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6973642f70686f6e652d6e756d6265722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/misd/phone-number-bundle)

This bundle integrates [Google's libphonenumber](https://github.com/googlei18n/libphonenumber) into your Symfony2/Symfony3 application through the [giggsey/libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php) port.

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

[](#installation)

1. Use Composer to download the PhoneNumberBundle:

    ```
    $ composer require misd/phone-number-bundle

    ```
2. Register the bundle in your application:

    ```
    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Misd\PhoneNumberBundle\MisdPhoneNumberBundle()
        );
    }

    ```

Usage
-----

[](#usage)

### Services

[](#services)

The following services are available:

ServiceIDlibphonenumber version`libphonenumber\PhoneNumberUtil``libphonenumber.phone_number_util``libphonenumber\geocoding\PhoneNumberOfflineGeocoder``libphonenumber.phone_number_offline_geocoder`&gt;=5.8.8`libphonenumber\ShortNumberInfo``libphonenumber.short_number_info`&gt;=5.8`libphonenumber\PhoneNumberToCarrierMapper``libphonenumber.phone_number_to_carrier_mapper`&gt;=5.8.8`libphonenumber\PhoneNumberToTimeZonesMapper``libphonenumber.phone_number_to_time_zones_mapper`&gt;=5.8.8So to parse a string into a `libphonenumber\PhoneNumber` object:

```
$phoneNumber = $container->get('libphonenumber.phone_number_util')->parse($string, PhoneNumberUtil::UNKNOWN_REGION);

```

### Doctrine mapping

[](#doctrine-mapping)

*Requires `doctrine/doctrine-bundle`.*

To persist `libphonenumber\PhoneNumber` objects, add the `Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType` mapping to your application's config:

```
// app/config.yml

doctrine:
    dbal:
        types:
            phone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType

```

You can then use the `phone_number` mapping:

```
/**
 * @ORM\Column(type="phone_number")
 */
private $phoneNumber;

```

This creates a `varchar(35)` column with a Doctrine mapping comment.

Note that if you're putting the `phone_number` type on an already-existing schema the current values must be converted to the `libphonenumber\PhoneNumberFormat::E164` format.

### Formatting `libphonenumber\PhoneNumber` objects

[](#formatting-libphonenumberphonenumber-objects)

#### Twig

[](#twig)

The `phone_number_format` filter can be used to format a phone number object. A `libphonenumber\PhoneNumberFormat` constant can be passed as argument to specify in which format the number should be printed.

For example, to format an object called `myPhoneNumber` in the `libphonenumber\PhoneNumberFormat::NATIONAL` format:

```
{{ myPhoneNumber|phone_number_format('NATIONAL') }}

```

By default phone numbers are formatted in the `libphonenumber\PhoneNumberFormat::INTERNATIONAL` format.

#### PHP template

[](#php-template)

The `format()` method in the `phone_number_format` helper takes two arguments: a `libphonenumber\PhoneNumber` object and an optional `libphonenumber\PhoneNumberFormat` constant name or value.

For example, to format `$myPhoneNumber` in the `libphonenumber\PhoneNumberFormat::NATIONAL` format, either use:

```

```

or:

```

```

By default phone numbers are formatted in the `libphonenumber\PhoneNumberFormat::INTERNATIONAL` format.

### Serializing `libphonenumber\PhoneNumber` objects

[](#serializing-libphonenumberphonenumber-objects)

*Requires `jms/serializer-bundle`.*

Instances of `libphonenumber\PhoneNumber` are automatically serialized in the E.164 format.

Phone numbers can be deserialized from an international format by setting the type to `libphonenumber\PhoneNumber`. For example:

```
use JMS\Serializer\Annotation\Type;

/**
 * @Type("libphonenumber\PhoneNumber")
 */
private $phoneNumber;

```

### Using `libphonenumber\PhoneNumber` objects in forms

[](#using-libphonenumberphonenumber-objects-in-forms)

You can use the `PhoneNumberType` (`tel` for Symfony &lt;= 2.7) form type to create phone number fields. There are two widgets available.

#### Single text field

[](#single-text-field)

A single text field allows the user to type in the complete phone number. When an international prefix is not entered, the number is assumed to be part of the set `default_region`. For example:

```
use libphonenumber\PhoneNumberFormat;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\FormBuilderInterface;

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('phone_number', PhoneNumberType::class, array('default_region' => 'GB', 'format' => PhoneNumberFormat::NATIONAL));
}

```

By default the `default_region` and `format` options are `PhoneNumberUtil::UNKNOWN_REGION` and `PhoneNumberFormat::INTERNATIONAL` respectively.

#### Country choice fields

[](#country-choice-fields)

The phone number can be split into a country choice and phone number text fields. This allows the user to choose the relevant country (from a customisable list) and type in the phone number without international dialling.

```
use libphonenumber\PhoneNumberFormat;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\FormBuilderInterface;

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('phone_number', PhoneNumberType::class, array('widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE, 'country_choices' => array('GB', 'JE', 'FR', 'US'), 'preferred_country_choices' => array('GB', 'JE')));
}

```

This produces the preferred choices of 'Jersey' and 'United Kingdom', and regular choices of 'France' and 'United States'.

By default the `country_choices` is empty, which means all countries are included, as is `preferred_country_choices`.

### Validating phone numbers

[](#validating-phone-numbers)

You can use the `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber` constraint to make sure that either a `libphonenumber\PhoneNumber` object or a plain string is a valid phone number. For example:

```
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;

/**
 * @AssertPhoneNumber
 */
private $phoneNumber;

```

You can set the default region through the `defaultRegion` property:

```
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;

/**
 * @AssertPhoneNumber(defaultRegion="GB")
 */
private $phoneNumber;

```

By default any valid phone number will be accepted. You can restrict the type through the `type` property, recognised values:

- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::ANY` (default)
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::FIXED_LINE`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::MOBILE`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::PAGER`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::PERSONAL_NUMBER`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::PREMIUM_RATE`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::SHARED_COST`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::TOLL_FREE`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::UAN`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::VOIP`
- `Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::VOICEMAIL`

(Note that libphonenumber cannot always distinguish between mobile and fixed-line numbers (eg in the USA), in which case it will be accepted.)

```
/**
 * @AssertPhoneNumber(type="mobile")
 */
private $mobilePhoneNumber;

```

### Translations

[](#translations)

The bundle contains translations for the form field and validation constraints.

In cases where a language uses multiple terms for mobile phones, the generic language locale will use the term 'mobile', while country-specific locales will use the relevant term. So in English, for example, `en` uses 'mobile', `en_US` uses 'cell' and `en_SG` uses 'handphone'.

If your language doesn't yet have translations, feel free to open a pull request to add them in!

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 83.6% 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 ~97 days

Recently: every ~81 days

Total

13

Last Release

3436d ago

### Community

Maintainers

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

---

Top Contributors

[![thewilkybarkid](https://avatars.githubusercontent.com/u/1784740?v=4)](https://github.com/thewilkybarkid "thewilkybarkid (153 commits)")[![xabbuh](https://avatars.githubusercontent.com/u/1957048?v=4)](https://github.com/xabbuh "xabbuh (5 commits)")[![rvanlaak](https://avatars.githubusercontent.com/u/2707563?v=4)](https://github.com/rvanlaak "rvanlaak (5 commits)")[![boekkooi](https://avatars.githubusercontent.com/u/399895?v=4)](https://github.com/boekkooi "boekkooi (2 commits)")[![giggsey](https://avatars.githubusercontent.com/u/305730?v=4)](https://github.com/giggsey "giggsey (2 commits)")[![helmut-hoffer-von-ankershoffen](https://avatars.githubusercontent.com/u/1826050?v=4)](https://github.com/helmut-hoffer-von-ankershoffen "helmut-hoffer-von-ankershoffen (2 commits)")[![ste93cry](https://avatars.githubusercontent.com/u/1770485?v=4)](https://github.com/ste93cry "ste93cry (2 commits)")[![zhil](https://avatars.githubusercontent.com/u/981783?v=4)](https://github.com/zhil "zhil (2 commits)")[![pdawczak](https://avatars.githubusercontent.com/u/601110?v=4)](https://github.com/pdawczak "pdawczak (1 commits)")[![peshi](https://avatars.githubusercontent.com/u/782150?v=4)](https://github.com/peshi "peshi (1 commits)")[![polc](https://avatars.githubusercontent.com/u/3513348?v=4)](https://github.com/polc "polc (1 commits)")[![giovkanata](https://avatars.githubusercontent.com/u/4223657?v=4)](https://github.com/giovkanata "giovkanata (1 commits)")[![brahaserhii](https://avatars.githubusercontent.com/u/2694457?v=4)](https://github.com/brahaserhii "brahaserhii (1 commits)")[![garak](https://avatars.githubusercontent.com/u/179866?v=4)](https://github.com/garak "garak (1 commits)")[![waaghals](https://avatars.githubusercontent.com/u/458580?v=4)](https://github.com/waaghals "waaghals (1 commits)")[![winzou](https://avatars.githubusercontent.com/u/702928?v=4)](https://github.com/winzou "winzou (1 commits)")[![ickbinhier](https://avatars.githubusercontent.com/u/2810904?v=4)](https://github.com/ickbinhier "ickbinhier (1 commits)")[![niketpathak](https://avatars.githubusercontent.com/u/10226768?v=4)](https://github.com/niketpathak "niketpathak (1 commits)")

---

Tags

bundlelibphonenumberphonenumberphone-numbertelephone number

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/20steps-phone-number-bundle/health.svg)

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

###  Alternatives

[odolbeau/phone-number-bundle

Integrates libphonenumber into your Symfony application

24910.3M11](/packages/odolbeau-phone-number-bundle)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[ronanguilloux/isocodes

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book and Music Industries, Phone numbers &amp; Zipcodes for many countries

8013.3M23](/packages/ronanguilloux-isocodes)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)[rollerworks/password-strength-bundle

Password-strength validator bundle for Symfony

1433.7M6](/packages/rollerworks-password-strength-bundle)[borales/yii2-phone-input

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

1341.6M6](/packages/borales-yii2-phone-input)

PHPackages © 2026

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