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

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

yjballestero/yii2-phone-input
=============================

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

022PHP

Since Mar 4Pushed 1y agoCompare

[ Source](https://github.com/YJBallestero/yii2-phone-input)[ Packagist](https://packagist.org/packages/yjballestero/yii2-phone-input)[ RSS](/packages/yjballestero-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/a6fc20e8f778fccb4f6e376aebc018a206ca21dda877df3f50223e88a0c15fba/68747470733a2f2f706f7365722e707567782e6f72672f796a62616c6c65737465726f2f796969322d70686f6e652d696e7075742f762f737461626c652e737667)](https://packagist.org/packages/yjballestero/yii2-phone-input)[![Total Downloads](https://camo.githubusercontent.com/f8cd8e3fdd5c87500b0e09cb4de9d56bc0329bf03055ab44429d6e25c230d67c/68747470733a2f2f706f7365722e707567782e6f72672f796a62616c6c65737465726f2f796969322d70686f6e652d696e7075742f646f776e6c6f6164732e737667)](https://packagist.org/packages/yjballestero/yii2-phone-input)[![Latest Unstable Version](https://camo.githubusercontent.com/6fcaeef9333b7ea05c502021006cf337d29b9b15ef7659ecd601871230a04ed0/68747470733a2f2f706f7365722e707567782e6f72672f796a62616c6c65737465726f2f796969322d70686f6e652d696e7075742f762f756e737461626c652e737667)](https://packagist.org/packages/yjballestero/yii2-phone-input)[![License](https://camo.githubusercontent.com/8236feb895aae1b6f83c93962fc17d38f66571018ead13c7827ae175c45d0951/68747470733a2f2f706f7365722e707567782e6f72672f796a62616c6c65737465726f2f796969322d70686f6e652d696e7075742f6c6963656e73652e737667)](https://packagist.org/packages/yjballestero/yii2-phone-input)[![Build Status](https://camo.githubusercontent.com/3d4d70603895d8f6a716b5785f7f0714c77b3d47a5b6b41a239edc45b40fc02f/68747470733a2f2f7472617669732d63692e6f72672f796a62616c6c65737465726f2f796969322d70686f6e652d696e7075742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yjballestero/yii2-phone-input)

Requirements
------------

[](#requirements)

This extension uses:

- PHP 8.0+.
- Yii2 2.0.45+

- [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 "yjballestero/yii2-phone-input" "*"
```

or add

```
"yjballestero/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 yjballestero\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 yjballestero\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 yjballestero\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 yjballestero\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 yjballestero\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;

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

Thanks to this behavior, you can also save the country code of the phone number in the database. Just add your attribute like `countryCodeAttribute` and it will be inserted into the database with the phone number.

```
namespace frontend\models;

use yjballestero\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

17

—

LowBetter than 6% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 73.7% 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/2b47a628efd31e556867293e4ddbfd9a9f903d27da860e6298f842dccff7e386?d=identicon)[yjballestero](/maintainers/yjballestero)

---

Top Contributors

[![Borales](https://avatars.githubusercontent.com/u/1118933?v=4)](https://github.com/Borales "Borales (42 commits)")[![YJBallestero](https://avatars.githubusercontent.com/u/1728320?v=4)](https://github.com/YJBallestero "YJBallestero (4 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)")[![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)")[![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)")

### Embed Badge

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

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

###  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)
