miserenkov/yii2-phone-validator

Yii2 phone validator

Installs: 21 923

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

v1.2 2023-03-31 17:16 UTC

This package is auto-updated.

Last update: 2024-10-30 01:37:12 UTC


README

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()],
        // ...
    ];
}