D
D
des1roer2015-05-05 08:15:21
Yii
des1roer, 2015-05-05 08:15:21

Yii how to change validation dynamically?

There is an input field. Suppose it can be first numeric and then text. How to check what the user enters?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Frank, 2015-05-05
@Akellacom

Use scripts in Yii or write your own rule for validation
Here is information on scripts and
validation :

S
Sergey, 2015-05-05
@butteff

Write your validation rule like this:

public function rules() {
  return [
    ['input', 'required'],
    ['input', function($attribute, $params) {
      if (is_integer($this->$attribute)) {
 				//если число
 				if ($this->attribute < 10) {
 					return $this->addError($attribute, 'Число должно быть больше 10');
 				}
      }

      if (is_string($this->$attribute)) {
        //ecли строка
      }			
  }],
];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question