Skip to content

miserenkov/yii2-phone-validator

Repository files navigation

Yii2 Phone Validator

Yii2 validator for phone numbers

License Latest Stable Version Latest Unstable Version Total Downloads Build Status

Support

GitHub issues.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist miserenkov/yii2-phone-validator "^1.0"

or add

"miserenkov/yii2-phone-validator": "^1.0"

to the require section of your composer.json file.

Basic usages

With fixed country value

public function rules()
{
    return [
        // ...
        ['phone', \miserenkov\validators\PhoneValidator::className(), 'country' => 'UA'],
        // ...
    ];
}

With fixed country attribute

public function rules()
{
    return [
        // ...
        ['country', 'string'],
        ['phone', \miserenkov\validators\PhoneValidator::className(), 'countryAttribute' => 'country'],
        // ...
    ];
}

With fixed countries value

public function rules()
{
    return [
        // ...
        ['phone', \miserenkov\validators\PhoneValidator::className(), 'countries' => ['UA', 'RU', 'US', /*...*/]],
        // ...
    ];
}

With all countries

public function rules()
{
    return [
        // ...
        ['phone', \miserenkov\validators\PhoneValidator::className()],
        // ...
    ];
}