PHPackages                             neobog/yii2-phone-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. neobog/yii2-phone-input

ActiveYii2-extension

neobog/yii2-phone-input
=======================

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

0321PHP

Since Oct 31Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#yii2-international-telephone-numbers---asset-bundle-behavior-validator-widget)

[![Latest Stable Version](https://camo.githubusercontent.com/bbcda05b52188dde6ec625effe8513c41b329569b4c96ee8108d730596226516/68747470733a2f2f706f7365722e707567782e6f72672f626f72616c65732f796969322d70686f6e652d696e7075742f762f737461626c652e737667)](https://packagist.org/packages/borales/yii2-phone-input)[![Total Downloads](https://camo.githubusercontent.com/a38408f10aa78a29ef58beedc1fd95a15f3b04f562c92d94524929d6d9cd68cb/68747470733a2f2f706f7365722e707567782e6f72672f626f72616c65732f796969322d70686f6e652d696e7075742f646f776e6c6f6164732e737667)](https://packagist.org/packages/borales/yii2-phone-input)[![Latest Unstable Version](https://camo.githubusercontent.com/20983400101ab02ae65898a0b54877c307d8aa1e09d5935d83d51f5a17624beb/68747470733a2f2f706f7365722e707567782e6f72672f626f72616c65732f796969322d70686f6e652d696e7075742f762f756e737461626c652e737667)](https://packagist.org/packages/borales/yii2-phone-input)[![License](https://camo.githubusercontent.com/1c73a9a109ee0e66e7bf242151a260809a683b6bbb9462134b6aa6b09bff35f1/68747470733a2f2f706f7365722e707567782e6f72672f626f72616c65732f796969322d70686f6e652d696e7075742f6c6963656e73652e737667)](https://packagist.org/packages/borales/yii2-phone-input)[![Build Status](https://camo.githubusercontent.com/b59742e3758986dfaa96c467508f7e19893c435436c661b74ace1ff7e3756e9a/68747470733a2f2f7472617669732d63692e6f72672f426f72616c65732f796969322d70686f6e652d696e7075742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Borales/yii2-phone-input)

This extension uses 2 libraries:

- [A jQuery plugin for entering and validating international telephone numbers](https://github.com/Bluefieldscom/intl-tel-input)
- [PHP version of Google's phone number handling library](https://github.com/giggsey/libphonenumber-for-php)

Original demo can be found here - .

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ php composer.phar require "borales/yii2-phone-input" "*"
```

or add

```
"borales/yii2-phone-input": "*"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

[![Phone input](screenshot.png "Phone input")](screenshot.png)

Using as an `ActiveField` widget with the preferred countries on the top:

```
use borales\extensions\phoneInput\PhoneInput;

echo $form->field($model, 'phone_number')->widget(PhoneInput::className(), [
    'jsOptions' => [
        'preferredCountries' => ['no', 'pl', 'ua'],
    ]
]);
```

Using as a simple widget with the limited countries list:

```
use borales\extensions\phoneInput\PhoneInput;

echo PhoneInput::widget([
    'name' => 'phone_number',
    'jsOptions' => [
        'allowExtensions' => true,
        'onlyCountries' => ['no', 'pl', 'ua'],
    ]
]);
```

Using phone validator in a model (validates the correct country code and phone format):

```
namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputValidator;

class Company extends Model
{
    public $phone;

    public function rules()
    {
        return [
            [['phone'], 'string'],
            [['phone'], PhoneInputValidator::className()],
        ];
    }
}
```

or if you need to validate phones of some countries:

```
namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputValidator;

class Company extends Model
{
    public $phone;

    public function rules()
    {
        return [
            [['phone'], 'string'],
            // [['phone'], PhoneInputValidator::className(), 'region' => 'UA'],
            [['phone'], PhoneInputValidator::className(), 'region' => ['PL', 'UA']],
        ];
    }
}
```

Using phone behavior in a model (auto-formats phone string to the required phone format):

```
namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;

    public function behaviors()
    {
        return [
            'phoneInput' => PhoneInputBehavior::className(),
        ];
    }
}
```

You can also thanks to this behavior save to database country code of the phone number. Just add your attribute as `countryCodeAttribute` and it'll be inserted into database with the phone number.

```
namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;
    public $countryCode;

    public function behaviors()
    {
        return [
            [
                'class' => PhoneInputBehavior::className(),
                'countryCodeAttribute' => 'countryCode',
            ],
        ];
    }
}
```

> Note: `nationalMode` option is very important! In case if you want to manage phone numbers with country/operator code

- you have to set `nationalMode: false` in widget options (for example, `PhoneInput::widget(...options, ['jsOptions' => ['nationalMode' => false]])`).

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% 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.

### Community

Maintainers

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

---

Top Contributors

[![Borales](https://avatars.githubusercontent.com/u/1118933?v=4)](https://github.com/Borales "Borales (42 commits)")[![Neobog](https://avatars.githubusercontent.com/u/33122231?v=4)](https://github.com/Neobog "Neobog (3 commits)")[![reastyn](https://avatars.githubusercontent.com/u/6328667?v=4)](https://github.com/reastyn "reastyn (2 commits)")[![mzglinski](https://avatars.githubusercontent.com/u/23341314?v=4)](https://github.com/mzglinski "mzglinski (1 commits)")[![nandes2062](https://avatars.githubusercontent.com/u/6126258?v=4)](https://github.com/nandes2062 "nandes2062 (1 commits)")[![lars-t](https://avatars.githubusercontent.com/u/7504335?v=4)](https://github.com/lars-t "lars-t (1 commits)")[![demenkov](https://avatars.githubusercontent.com/u/1043113?v=4)](https://github.com/demenkov "demenkov (1 commits)")[![RichWeber](https://avatars.githubusercontent.com/u/1702252?v=4)](https://github.com/RichWeber "RichWeber (1 commits)")[![sample-game](https://avatars.githubusercontent.com/u/12247435?v=4)](https://github.com/sample-game "sample-game (1 commits)")[![smichae](https://avatars.githubusercontent.com/u/5036176?v=4)](https://github.com/smichae "smichae (1 commits)")[![Spell6inder](https://avatars.githubusercontent.com/u/2795910?v=4)](https://github.com/Spell6inder "Spell6inder (1 commits)")[![Stern87](https://avatars.githubusercontent.com/u/13180074?v=4)](https://github.com/Stern87 "Stern87 (1 commits)")

### Embed Badge

![Health badge](/badges/neobog-yii2-phone-input/health.svg)

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

PHPackages © 2026

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