2017 © Pedro Peláez
 

yii2-extension yii2-phone-input

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

image

borales/yii2-phone-input

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

  • Sunday, June 17, 2018
  • by borales
  • Repository
  • 11 Watchers
  • 70 Stars
  • 79,693 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 37 Forks
  • 18 Open issues
  • 8 Versions
  • 19 % Grown

The README.md

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

Latest Stable Version Total Downloads Latest Unstable Version License Build Status, (*1)

This extension uses 2 libraries:, (*2)

Original demo can be found here - http://jackocnr.com/intl-tel-input.html., (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

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

or add, (*6)

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

to the require section of your composer.json file., (*7)

Usage

Phone input, (*8)

Using as an ActiveField widget with the preferred countries on the top:, (*9)

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:, (*10)

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):, (*11)

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:, (*12)

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):, (*13)

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., (*14)

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]]))., (*15)

The Versions

17/06 2018

dev-master

9999999-dev https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

11/06 2017

0.1.1

0.1.1.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

10/06 2017

0.1.0

0.1.0.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

05/06 2016

0.0.5

0.0.5.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

12/04 2016

0.0.4

0.0.4.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

16/03 2016

0.0.3

0.0.3.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

04/03 2016

0.0.2

0.0.2.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers

10/06 2015

0.0.1

0.0.1.0 https://github.com/Borales/yii2-phone-input

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Borales (Alexandr Bordun)

yii2 libphonenumber intl-tel-input international telephone numbers