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

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

nepada/phone-number-input
=========================

Phone number form input for Nette forms.

v1.3.4(5mo ago)615.1k↓20.5%[3 PRs](https://github.com/nepada/phone-number-input/pulls)BSD-3-ClausePHPPHP &gt;=8.1.0 &lt;8.6CI failing

Since Mar 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/nepada/phone-number-input)[ Packagist](https://packagist.org/packages/nepada/phone-number-input)[ RSS](/packages/nepada-phone-number-input/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (19)Versions (17)Used By (0)

Phone number form input
=======================

[](#phone-number-form-input)

[![Build Status](https://github.com/nepada/phone-number-input/workflows/CI/badge.svg)](https://github.com/nepada/phone-number-input/actions?query=workflow%3ACI+branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/fa2d84561edf1c8c27750ada7c82fdc3d8562ffff240025464ecaaa937abadc3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e65706164612f70686f6e652d6e756d6265722d696e7075742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/nepada/phone-number-input?branch=master)[![Downloads this Month](https://camo.githubusercontent.com/4c748236da44f625aec387b13aabfb716423742e2dd6525727fb5eafcb57af0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e65706164612f70686f6e652d6e756d6265722d696e7075742e737667)](https://packagist.org/packages/nepada/phone-number-input)[![Latest stable](https://camo.githubusercontent.com/3579719b9a29b30fe9b892388129b382ba41234e31f444cb6bc980d603371b87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65706164612f70686f6e652d6e756d6265722d696e7075742e737667)](https://packagist.org/packages/nepada/phone-number-input)

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

[](#installation)

Via Composer:

```
$ composer require nepada/phone-number-input
```

### Option A: install form container extension method via DI extension

[](#option-a-install-form-container-extension-method-via-di-extension)

```
extensions:
    - Nepada\Bridges\PhoneNumberInputDI\PhoneNumberInputExtension
```

It will register extension method `addPhoneNumber($name, $label = null, ?string $defaultRegionCode = null): PhoneNumberInput` to `Nette\Forms\Container`.

### Option B: use trait in your base form/container class

[](#option-b-use-trait-in-your-base-formcontainer-class)

You can also use `PhoneNumberInputMixin` trait in your base form/container class to add method `addPhoneNumber($name, $label = null, ?string $defaultRegionCode = null): PhoneNumberInput`.

Example:

```
trait FormControls
{

    use Nepada\Bridges\PhoneNumberInputForms\PhoneNumberInputMixin;

    public function addContainer($name)
    {
        $control = new Container;
        $control->setCurrentGroup($this->getCurrentGroup());
        if ($this->currentGroup !== null) {
            $this->currentGroup->add($control);
        }
        return $this[$name] = $control;
    }

}

class Container extends Nette\Forms\Container
{

    use FormControls;

}

class Form extends Nette\Forms\Form
{

    use FormControls;

}
```

Usage
-----

[](#usage)

`PhoneNumberInput` is form control that uses phone number value object to represent its value (see [brick/phonenumber](https://github.com/brick/phonenumber) for further details). It automatically validates the user input and `getValue()` method always returns `PhoneNumber` instance, or `null` if the input is not filled.

```
$PhoneNumberInput = $form->addPhoneNumber('phone');
$PhoneNumberInput->setValue('invalid'); // \InvalidArgumentException is thrown
$PhoneNumberInput->setValue('+420 212 345 678'); // the value is internally converted to PhoneNumber value object
$PhoneNumberInput->getValue(); // PhoneNumber instance for +420212345678
```

### Validation

[](#validation)

The default validation is fairly lenient - it performs only basic check based on the parsed region and the length of the number.

#### Strict validation

[](#strict-validation)

You can add a more strict validation rule `PhoneNumberInput::VALID_STRICT`. This rule validates the content against regular expressions from metadata database.

**Warning:** you must make sure you've got up-to-date metadata library, otherwise you risk running into false positives and false negatives during the validation. The metadata are provided by [giggsey/libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php) for backend validation and [libphonenumber-js](https://yarnpkg.com/package/libphonenumber-js) for client side validation.

#### Region validation

[](#region-validation)

You can restrict the input to accept only numbers from specific region(s):

```
// Specify one or more ISO 3166-1 alpha-2 country codes
$input->addRule(PhoneNumberInput::REGION, 'Only US phone numbers are allowed', 'US');
$input->addRule(PhoneNumberInput::REGION, 'Only Czech and Slovak phone numbers are allowed', ['CZ', 'SK']);
```

### Default region code

[](#default-region-code)

When creating the input you may specify default region code (ISO 3166-1 alpha-2 country code), e.g. `$form->addPhoneNumber('phone', 'Phone', 'CZ')`. This has two effects:

1. User may omit the country code prefix for this region in the input field, e.g. `212 345 678` is interpreted as `+420 212 345 678`.
2. When rendering the input, phone numbers for this region are displayed in national format instead of international, i.e. the country code is omitted.

### Client side validation

[](#client-side-validation)

This package comes with client side validation built on top of [libphonenumber-js](https://yarnpkg.com/package/libphonenumber-js). It is published as npm package [@nepada/phone-number-input](https://yarnpkg.com/package/@nepada/phone-number-input).

`libphonenumber-js` provides several [different metadata sets](https://gitlab.com/catamphetamine/libphonenumber-js#customizing-metadata). You should choose the one based on your validation needs (e.g. if you don't need strict validation, go with `min`), or build your own custom metadata set.

#### Using precompiled bundle

[](#using-precompiled-bundle)

Using precompiled bundles is the quick'n'dirty way of getting client side validation to work.

```

```

#### Building your own bundle

[](#building-your-own-bundle)

It is highly recommended to install the client side package via nmp and compile your own bundle. This way you can use your custom build of metadata set mentioned earlier.

Here is an example script for initialization of phone number input and Nette forms.

```
import Nette from 'nette-forms';
import initializePhoneNumberInput from '@nepada/phone-number-input';
import metadata from 'libphonenumber-js/metadata.full';
// OR
// import metadata from 'libphonenumber-js/metadata.min';
// OR
// import metadata from 'libphonenumber-js/metadata.mobile';
// OR
// import metadata from './metadata.custom.js';

initializePhoneNumberInput(Nette, metadata);
Nette.initOnLoad();
```

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance79

Regular maintenance activity

Popularity30

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 54.1% 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 ~188 days

Recently: every ~196 days

Total

12

Last Release

176d ago

PHP version history (5 changes)v1.0.0PHP &gt;=7.4.0

v1.2.1PHP &gt;=7.4.0 &lt;8.3

v1.3.0PHP &gt;=8.1.0 &lt;8.4

v1.3.2PHP &gt;=8.1.0 &lt;8.5

v1.3.4PHP &gt;=8.1.0 &lt;8.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b4780fe328102c4572737db639653c29d3081d1d3e051467f00d7f09a776399?d=identicon)[xificurk](/maintainers/xificurk)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (178 commits)")[![xificurk](https://avatars.githubusercontent.com/u/117465?v=4)](https://github.com/xificurk "xificurk (151 commits)")

---

Tags

netteforminputphone-number

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.3k64.2M576](/packages/nette-php-generator)[robinherbots/jquery.inputmask

Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.

6.5k276.6k4](/packages/robinherbots-jqueryinputmask)[nette/code-checker

✅ Nette CodeChecker: A simple tool to check source code against a set of Nette coding standards.

881.7M6](/packages/nette-code-checker)[kartik-v/yii2-widget-rating

A Yii2 widget for the simple yet powerful bootstrap-star-rating plugin with fractional rating support (sub repo split from yii2-widgets)

444.1M8](/packages/kartik-v-yii2-widget-rating)[harvesthq/chosen

Chosen is a JavaScript plugin that makes select boxes user-friendly. It is currently available in both jQuery and Prototype flavors.

385.2M12](/packages/harvesthq-chosen)[kartik-v/yii2-widget-switchinput

A Yii2 wrapper widget for the Bootstrap Switch plugin to use checkboxes &amp; radios as toggle switchinputes (sub repo split from yii2-widgets)

384.4M13](/packages/kartik-v-yii2-widget-switchinput)

PHPackages © 2026

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