Validators for Yii2
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yiier/yii2-validators "*"
or add
"yiier/yii2-validators": "*"
to the require section of your composer.json
file.
中国身份证号码验证
public function rules()
{
return [
// ...
['id_card', \yiier\validators\IdCardValidator::class],
// code
];
}
Array Validator
public function rules()
{
return [
// ...
['product_ids', \yiier\validators\ArrayValidator::class],
// code
];
}
Phone Validator
public function rules()
{
return [
// ...
['phone', \yiier\validators\PhoneValidator::class],
// code
];
}
Money Validator
public function rules()
{
return [
// ...
['amount', \yiier\validators\MoneyValidator::class],
['amount', \yiier\validators\MoneyValidator::class, 'allowsNegative' => true],
// code
];
}
……