yii2, you can use with Class yii\validators\EachValidator
VIEW
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'dynamic_name[]')->textInput() ?>
<?= Html::submitButton('Submit', ['class' => 'btn', 'name' => 'hash-button']) ?>
<?php ActiveForm::end(); ?>
MODEL
class MyModel extends Model
{
public $dynamic_name = [];
public function rules()
{
return [
// checks if every dynamic_name is an integer
['dynamic_name', 'each', 'rule' => ['integer']],
]
}
}
Note: This validator will not work with inline validation rules in case of usage outside the model scope, e.g. via validate() method.
Link: http://www.yiiframework.com/doc-2.0/yii-validators-eachvalidator.html