Yii2 validator for phone numbers
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.
public function rules()
{
return [
// ...
['phone', \miserenkov\validators\PhoneValidator::className(), 'country' => 'UA'],
// ...
];
}
public function rules()
{
return [
// ...
['country', 'string'],
['phone', \miserenkov\validators\PhoneValidator::className(), 'countryAttribute' => 'country'],
// ...
];
}
public function rules()
{
return [
// ...
['phone', \miserenkov\validators\PhoneValidator::className(), 'countries' => ['UA', 'RU', 'US', /*...*/]],
// ...
];
}
public function rules()
{
return [
// ...
['phone', \miserenkov\validators\PhoneValidator::className()],
// ...
];
}