PHPackages                             deshengk/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. deshengk/yii2-phone-input

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

deshengk/yii2-phone-input
=========================

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

1.0.13(1y ago)14.6k↓11.1%1BSD-3-ClausePHP

Since Jun 10Pushed 1y agoCompare

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

READMEChangelog (10)Dependencies (3)Versions (25)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/fb92fd0ae543d5d9edb21a2e7ed5da579293f95613ad8f4746ad5df493c92c26/68747470733a2f2f706f7365722e707567782e6f72672f64657368656e676b2f796969322d70686f6e652d696e7075742f762f737461626c652e737667)](https://packagist.org/packages/deshengk/yii2-phone-input)[![Total Downloads](https://camo.githubusercontent.com/2dbb076af42de4bf7be80c4b7d8b7d239e0857566400290cb4f01124cb3478c0/68747470733a2f2f706f7365722e707567782e6f72672f64657368656e676b2f796969322d70686f6e652d696e7075742f646f776e6c6f6164732e737667)](https://packagist.org/packages/deshengk/yii2-phone-input)[![Latest Unstable Version](https://camo.githubusercontent.com/d004bad009f9367646c0bf51ad5be94e66f3e8784731949e31a4dd94c461de6a/68747470733a2f2f706f7365722e707567782e6f72672f64657368656e676b2f796969322d70686f6e652d696e7075742f762f756e737461626c652e737667)](https://packagist.org/packages/deshengk/yii2-phone-input)[![License](https://camo.githubusercontent.com/60a6a40295d07bf9c3c9fb2669d2a45071e62ab7261cc95a54d7f29ddaa9c43f/68747470733a2f2f706f7365722e707567782e6f72672f64657368656e676b2f796969322d70686f6e652d696e7075742f6c6963656e73652e737667)](https://packagist.org/packages/deshengk/yii2-phone-input)[![Build Status](https://camo.githubusercontent.com/25e1ea8a9e6b80e46926ff2372ab53d09b0f59308fdaa041aae17b183728eff3/68747470733a2f2f7472617669732d63692e6f72672f64657368656e676b2f796969322d70686f6e652d696e7075742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/deshengk/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 "deshengk/yii2-phone-input" "*"
```

or add

```
"deshengk/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 deshengk\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 deshengk\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 deshengk\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 deshengk\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 deshengk\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 deshengk\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

42

—

FairBetter than 90% of packages

Maintenance42

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~153 days

Recently: every ~83 days

Total

24

Last Release

468d ago

Major Versions

0.3.0 → 1.0.02021-08-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/1537a579e5efe6d0958a6c8e7579d298cd4cf965364b391dcdb11c908a6a3ea2?d=identicon)[deshengk](/maintainers/deshengk)

---

Top Contributors

[![Borales](https://avatars.githubusercontent.com/u/1118933?v=4)](https://github.com/Borales "Borales (42 commits)")[![DavidKongDesheng](https://avatars.githubusercontent.com/u/5900244?v=4)](https://github.com/DavidKongDesheng "DavidKongDesheng (9 commits)")[![desheng-ds](https://avatars.githubusercontent.com/u/86274091?v=4)](https://github.com/desheng-ds "desheng-ds (8 commits)")[![reastyn](https://avatars.githubusercontent.com/u/6328667?v=4)](https://github.com/reastyn "reastyn (2 commits)")[![nandes2062](https://avatars.githubusercontent.com/u/6126258?v=4)](https://github.com/nandes2062 "nandes2062 (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)")[![demenkov](https://avatars.githubusercontent.com/u/1043113?v=4)](https://github.com/demenkov "demenkov (1 commits)")[![lars-t](https://avatars.githubusercontent.com/u/7504335?v=4)](https://github.com/lars-t "lars-t (1 commits)")[![mzglinski](https://avatars.githubusercontent.com/u/23341314?v=4)](https://github.com/mzglinski "mzglinski (1 commits)")

---

Tags

libphonenumberyii2intl-tel-inputinternational telephone numbers

### Embed Badge

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

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

###  Alternatives

[borales/yii2-phone-input

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

1341.6M6](/packages/borales-yii2-phone-input)[codeonyii/yii2-at-least-validator

Validates at least one (or more) attributes.

28253.5k1](/packages/codeonyii-yii2-at-least-validator)[arogachev/yii2-many-to-many

Many-to-many ActiveRecord relation for Yii 2 framework

3541.2k4](/packages/arogachev-yii2-many-to-many)[yii2mod/yii2-validators

Collection of useful validators for Yii Framework 2.0

1816.8k](/packages/yii2mod-yii2-validators)

PHPackages © 2026

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