Yii2 Phone Validator
Yii2 validator for phone numbers, (*1)
, (*2)
Support
GitHub issues., (*3)
Installation
The preferred way to install this extension is through composer., (*4)
Either run, (*5)
php composer.phar require --prefer-dist miserenkov/yii2-phone-validator "^1.0"
or add, (*6)
"miserenkov/yii2-phone-validator": "^1.0"
to the require section of your composer.json
file., (*7)
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()],
// ...
];
}