The format of the number must match the regular expression specified in [[integerPattern]] or [[numberPattern]]. Optionally, you may configure the [[max]] and [[min]] properties to ensure the number is within certain range.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Validator
Example #1
0
 /**
  * Валидирует массивы с ИД на корректность данных и их количество.
  *
  * @param string $attribute the attribute currently being validated
  * @param array $params the additional name-value pairs given in the rule
  */
 public function validateCount($attribute, $params)
 {
     //echo'<pre>'; print_r($this->$attribute);echo'</pre>';//die;
     if (!$this->hasErrors()) {
         $dotaParams = DotaParams::loadParams();
         $slots_field = $this->getSlotsField($attribute, $this->draft_id);
         $slots_count = $dotaParams->{$slots_field};
         //echo'<pre>'; print_r($slots_count);echo'</pre>';//die;
         //echo'<pre>'; print_r($slots_field);echo'</pre>';//die;
         //echo'<pre>'; print_r($this->draft_id);echo'</pre>';//die;
         //echo'<pre>'; print_r($this->$attribute);echo'</pre>';//die;
         if (count($this->{$attribute}) != $slots_count) {
             $this->addError($attribute, Yii::t('app', 'FANTASY_RATE_SEND_ERROR_SLOTS'));
         }
         $NumberValidator = new NumberValidator();
         $NumberValidator->integerOnly = true;
         $attr_value = $this->{$attribute};
         foreach ($attr_value as $v) {
             if (!$NumberValidator->validate($v)) {
                 $this->addError($attribute, Yii::t('app', 'FANTASY_RATE_SEND_ERROR_INT'));
                 break;
             }
         }
     }
 }
    private function validateAsNumber($model,$attribute){
        $validator = new NumberValidator();

        if(!$validator->validate($model->$attribute, $error)){
            $model->addError('username' ,'Must be a Valid Number');
        }
    }
Example #3
0
 /**
  * @return array
  */
 public function rules()
 {
     return [['operatorId', 'exist', 'targetClass' => Operator::className(), 'targetAttribute' => '_id'], ['period', function ($attribute) {
         $monthValidator = new NumberValidator(['integerOnly' => true, 'min' => 1, 'max' => 12]);
         $yearValidator = new NumberValidator(['integerOnly' => true, 'min' => 2014]);
         if (!$monthValidator->validate($this->period['month']) || !$yearValidator->validate($this->period['year'])) {
             $this->addError($attribute, "«{attribute}» имеет неверный формат");
         }
     }]];
 }
Example #4
0
 public function validateAttribute($model, $attribute)
 {
     $result = parent::validateAttribute($model, $attribute);
     /* Not sure about this, left it here in case
     		if(
     			count($model->getErrors($attribute)) <= 0 && 
     			$this->format === null && 
     			$this->format !== false
     		){
     			
     			$value = $model->$attribute;
     			
     			if(preg_match('#^0#', $value)){
     				// Starts with 0, string it
     				$model->$attribute = $value;
     			}elseif(preg_match('#([0-9]+)\.([0-9]+)#')){
     				$model->$attribute = floatval($value);
     			}else{
     				$model->$attribute = $value;
     			}
     			
     		}else{
     			$model->$attribute = $this->format($model->$attribute);
     		}
     		*/
     $model->{$attribute} = $this->format($model->{$attribute});
     return $result;
 }
 public function __construct($config = [])
 {
     $config['integerOnly'] = true;
     $config['min'] = 1;
     $config['max'] = 10000;
     parent::__construct($config);
 }
Example #6
0
 /**
  * Валидирует массивы с ИД на корректность данных и их количество.
  *
  * @param string $attribute the attribute currently being validated
  * @param array $params the additional name-value pairs given in the rule
  */
 public function validateCount($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $game_params = PokerParams::loadParams();
         $slots_count = $game_params->players_slots;
         if (count($this->{$attribute}) != $slots_count) {
             $this->addError($attribute, Yii::t('app', 'FANTASY_RATE_SEND_ERROR_SLOTS'));
         }
         $NumberValidator = new NumberValidator();
         $NumberValidator->integerOnly = true;
         $attr_value = $this->{$attribute};
         foreach ($attr_value as $v) {
             if (!$NumberValidator->validate($v)) {
                 $this->addError($attribute, Yii::t('app', 'FANTASY_RATE_SEND_ERROR_INT'));
                 break;
             }
         }
     }
 }
 /**
  * Phone number validation
  *
  * @param $attribute
  */
 public function validatePhones($attribute)
 {
     $items = $this->{$attribute};
     if (!is_array($items)) {
         $items = [];
     }
     $multiple = true;
     if (!is_array($items)) {
         $multiple = false;
         $items = (array) $items;
     }
     foreach ($items as $index => $item) {
         $validator = new NumberValidator();
         $error = null;
         $validator->validate($item, $error);
         if (!empty($error)) {
             $key = $attribute . ($multiple ? '[' . $index . ']' : '');
             $this->addError($key, $error);
         }
     }
 }
Example #8
0
 /**
  * validate official QQ
  * @return string
  */
 public function actionKefuQqValidate()
 {
     $model = new KefuQqValidateForm();
     $numberValid = new NumberValidator();
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         if (!$numberValid->validate($model->qq)) {
             //$model->addError('qq','输入的QQ号码无效!');
             \Yii::$app->session->setFlash('error', '输入的QQ号码无效!');
             return $this->render('validate-qq', ['model' => $model]);
         }
         if ($model->validateQQ()) {
             //$model->addError('qq','此QQ号码为官方QQ号码,请放心!');
             \Yii::$app->session->setFlash('success', '此QQ号码为官方QQ号码,请放心!');
             return $this->render('validate-qq', ['model' => $model]);
         } else {
             //$model->addError('qq','该QQ不是官方QQ,请谨防上当受骗!');
             \Yii::$app->session->setFlash('error', '该QQ不是官方QQ,请谨防上当受骗!');
             return $this->render('validate-qq', ['model' => $model]);
         }
     }
     return $this->render('validate-qq', ['model' => $model]);
 }
Example #9
0
 public function validateMatrix($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $NumberValidator = new NumberValidator();
         $NumberValidator->integerOnly = false;
         //echo'<pre>';print_r($this->grid);echo'</pre>';die;
         for ($pos = 0; $pos < count($this->positions_key); $pos++) {
             $err = false;
             for ($usr = 0; $usr < count($this->users_key); $usr++) {
                 $v = $this->grid[$this->positions_key[$pos]][$this->users_key[$usr]];
                 if (!$NumberValidator->validate($v)) {
                     $this->addError($attribute, 'Значение должно быть числом');
                     $err = true;
                     break;
                 }
             }
             if ($err === true) {
                 break;
             }
         }
     }
 }
 public function run($id)
 {
     $validator = new NumberValidator();
     $validator->integerOnly = true;
     if (!$validator->validate($id, $error)) {
         throw new HttpException(500, $error);
     }
     $query = (new $this->treeModelName())->find();
     $nodes = [];
     if ($id == 0) {
         $nodes = $query->roots()->all();
     } else {
         $parent = $query->where(['id' => $id])->one();
         if ($parent === null) {
             throw new NotFoundHttpException(Yii::t('gtreetable', 'Position indicated by parent ID is not exists!'));
         }
         $nodes = $parent->children(1)->all();
     }
     $result = [];
     foreach ($nodes as $node) {
         $result[] = ['id' => $node->getPrimaryKey(), 'name' => $node->getName(), 'level' => $node->getDepth(), 'type' => $node->getType()];
     }
     echo Json::encode(['nodes' => $result]);
 }
Example #11
0
 public function testCreateValidator()
 {
     $model = FakedValidationModel::createWithAttributes(['attr_test1' => 'abc', 'attr_test2' => '2013']);
     /* @var $numberVal NumberValidator */
     $numberVal = TestValidator::createValidator('number', $model, ['attr_test1']);
     $this->assertInstanceOf(NumberValidator::className(), $numberVal);
     $numberVal = TestValidator::createValidator('integer', $model, ['attr_test2']);
     $this->assertInstanceOf(NumberValidator::className(), $numberVal);
     $this->assertTrue($numberVal->integerOnly);
     $val = TestValidator::createValidator('boolean', $model, ['attr_test1', 'attr_test2'], ['on' => ['a', 'b']]);
     $this->assertInstanceOf(BooleanValidator::className(), $val);
     $this->assertSame(['a', 'b'], $val->on);
     $this->assertSame(['attr_test1', 'attr_test2'], $val->attributes);
     $val = TestValidator::createValidator('boolean', $model, ['attr_test1', 'attr_test2'], ['on' => ['a', 'b'], 'except' => ['c', 'd', 'e']]);
     $this->assertInstanceOf(BooleanValidator::className(), $val);
     $this->assertSame(['a', 'b'], $val->on);
     $this->assertSame(['c', 'd', 'e'], $val->except);
     $val = TestValidator::createValidator('inlineVal', $model, ['val_attr_a']);
     $this->assertInstanceOf(InlineValidator::className(), $val);
     $this->assertSame('inlineVal', $val->method);
 }
Example #12
0
 public function rules()
 {
     return [[['type', 'name'], RequiredValidator::className()], [['length', 'precision', 'scale'], NumberValidator::className()], [['is_not_null', 'is_unique', 'unsigned', 'isCompositeKey'], BooleanValidator::className()], [['name'], StringValidator::className(), 'max' => 50], [['comment', 'fk_name'], StringValidator::className(), 'max' => 255], [['type'], RangeValidator::className(), 'range' => $this->getTypeList()]];
 }
Example #13
0
 /**
  * https://github.com/yiisoft/yii2/issues/3118
  */
 public function testClientValidateComparison()
 {
     $val = new NumberValidator(['min' => 5, 'max' => 10]);
     $model = new FakedValidationModel();
     $js = $val->clientValidateAttribute($model, 'attr_number', new View(['assetBundles' => ['yii\\validators\\ValidationAsset' => true]]));
     $this->assertContains('"min":5', $js);
     $this->assertContains('"max":10', $js);
     $val = new NumberValidator(['min' => '5', 'max' => '10']);
     $model = new FakedValidationModel();
     $js = $val->clientValidateAttribute($model, 'attr_number', new View(['assetBundles' => ['yii\\validators\\ValidationAsset' => true]]));
     $this->assertContains('"min":5', $js);
     $this->assertContains('"max":10', $js);
     $val = new NumberValidator(['min' => 5.65, 'max' => 13.37]);
     $model = new FakedValidationModel();
     $js = $val->clientValidateAttribute($model, 'attr_number', new View(['assetBundles' => ['yii\\validators\\ValidationAsset' => true]]));
     $this->assertContains('"min":5.65', $js);
     $this->assertContains('"max":13.37', $js);
     $val = new NumberValidator(['min' => '5.65', 'max' => '13.37']);
     $model = new FakedValidationModel();
     $js = $val->clientValidateAttribute($model, 'attr_number', new View(['assetBundles' => ['yii\\validators\\ValidationAsset' => true]]));
     $this->assertContains('"min":5.65', $js);
     $this->assertContains('"max":13.37', $js);
 }
Example #14
0
 /**
  * Validate 'value' attribute against of 'value_type'.
  */
 public function validateValue($attribute, $params = [])
 {
     if ($this->required) {
         $required = Yii::createObject(['class' => \yii\validators\RequiredValidator::className(), 'message' => Yii::t('app', '{label} is required.', ['label' => $this->title])]);
         if (!$required->validate($this->{$attribute})) {
             $this->addError($attribute, $required->message);
             return;
         }
     } else {
         $value = $this->{$attribute};
         if ($value === null || $value === '') {
             return;
         }
     }
     switch ($this->value_type) {
         case static::TYPE_INT:
             $args = ['class' => NumberValidator::className(), 'integerOnly' => true, 'message' => 'Not an integer'];
             break;
         case static::TYPE_NUM:
             $args = ['class' => NumberValidator::className(), 'message' => 'Not a number'];
             break;
         case static::TYPE_EMAIL:
             $args = ['class' => EmailValidator::className(), 'message' => 'Not a valid email'];
             break;
         case static::TYPE_URL:
             $args = ['class' => UrlValidator::className(), 'message' => 'Not a valid url'];
             break;
         case static::TYPE_SWITCH:
             $args = ['class' => BooleanValidator::className(), 'message' => 'Must be boolean value'];
             break;
         case static::TYPE_TEXT:
         case static::TYPE_EDITOR:
         case static::TYPE_PASSWORD:
             $args = ['class' => StringValidator::className()];
             break;
         case static::TYPE_SELECT:
             $args = ['class' => RangeValidator::className(), 'range' => array_keys($this->options), 'message' => 'Invalid value'];
             break;
         default:
             throw new InvalidParamException('Unknown config type: ' . $this->value_type);
     }
     $validator = Yii::createObject($args);
     if (!$validator->validate($this->{$attribute})) {
         $this->addError($attribute, $validator->message);
     } else {
         $this->castType();
     }
 }
Example #15
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $js = "value = value && value.replace(/[ '’]/g, '').replace(/,/g, '.');";
     $jsExpression = new JsExpression($js) . parent::clientValidateAttribute($model, $attribute, $view);
     return $jsExpression;
 }
 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     $model->{$attribute} = str_replace(",", ".", $model->{$attribute});
     parent::validateAttribute($model, $attribute);
 }
 public function testEnsureCustomMessageIsSetOnValidateAttribute()
 {
     $val = new NumberValidator(['tooSmall' => '{attribute} is to small.', 'min' => 5]);
     $model = new FakedValidationModel();
     $model->attr_number = 0;
     $val->validateAttribute($model, 'attr_number');
     $this->assertTrue($model->hasErrors('attr_number'));
     $this->assertEquals(1, count($model->getErrors('attr_number')));
     $msgs = $model->getErrors('attr_number');
     $this->assertSame('attr_number is to small.', $msgs[0]);
 }
Example #18
0
 /**
  * @return array
  */
 public function rules()
 {
     return [['parent_id', 'validateParent'], ['label', StringValidator::className()], ['label', RequiredValidator::className()], ['path', StringValidator::className()], ['status', BooleanValidator::className()], ['order_num', NumberValidator::className()]];
 }
Example #19
0
 public function fieldTypeValidation()
 {
     // Messages
     $invalidMessage = "the input value has a not valid value.";
     // Validation by Input Type
     foreach ($this->fields as $field) {
         foreach ($field as $key => $value) {
             // Text
             if ($key === "type" && $value === "text") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // A pattern can be used
                     if (isset($field["pattern"])) {
                         $regexValidator = new RegularExpressionValidator(['pattern' => $field["pattern"]]);
                         if (!$regexValidator->validate($this->data[$field["name"]], $error)) {
                             $this->addError($field["name"], $field["label"], '', $error);
                         }
                     }
                 }
             }
             // Tel
             if ($key === "type" && $value === "tel") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // A pattern can be used
                     if (isset($field["pattern"])) {
                         $regexValidator = new RegularExpressionValidator(['pattern' => $field["pattern"]]);
                         if (!$regexValidator->validate($this->data[$field["name"]], $error)) {
                             $this->addError($field["name"], $field["label"], '', $error);
                         }
                     } else {
                         // By default, the number must be a international phone number
                         $phoneValidator = new PhoneValidator();
                         if (!$phoneValidator->validate($this->data[$field["name"]], $error)) {
                             $this->addError($field["name"], $field["label"], '', $error . ' ' . Yii::t("app", "It must has a internationally-standardized format\n                                (e.g. '+1 650-555-5555')"));
                         }
                     }
                 }
             }
             // Url
             if ($key === "type" && $value === "url") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // Config validator
                     $config = [];
                     // A pattern can be used
                     if (isset($field["pattern"])) {
                         $config['pattern'] = $field["pattern"];
                     }
                     $urlValidator = new UrlValidator($config);
                     if (!$urlValidator->validate($this->data[$field["name"]], $error)) {
                         $this->addError($field["name"], $field["label"], '', $error);
                     }
                 }
             }
             // Color
             if ($key === "type" && $value === "color") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // hex color invalid
                     if (!preg_match('/^#[a-f0-9]{6}$/i', $this->data[$field["name"]])) {
                         $this->addError($field["name"], $field["label"], '', $invalidMessage . ' ' . Yii::t("app", "It must be a hexadecimal color string (e.g. '#FFFFFF')."));
                     }
                 }
             }
             // Password
             if ($key === "type" && $value === "password") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     $newData = trim($this->data[$field["name"]]);
                     // Remove spaces
                     $stringValidator = new StringValidator(['min' => 6]);
                     if (!$stringValidator->validate($newData, $error)) {
                         $this->addError($field["name"], $field["label"], '', $error);
                     }
                     // A pattern can be used
                     if (isset($field["pattern"])) {
                         $regexValidator = new RegularExpressionValidator(['pattern' => $field["pattern"]]);
                         if (!$regexValidator->validate($this->data[$field["name"]], $error)) {
                             $this->addError($field["name"], $field["label"], '', $error);
                         }
                     }
                 }
             }
             // Email
             if ($key === "type" && $value === "email") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // Config email validator
                     $config = [];
                     // A pattern can be used
                     if (isset($field["pattern"])) {
                         $config['pattern'] = $field["pattern"];
                     }
                     // Whether to check if email's domain exists and has either an A or MX record.
                     // Be aware that this check can fail due temporary DNS problems
                     // even if the email address is valid and an email would be deliverable
                     if (isset($field["data-check-dns"])) {
                         $config['checkDNS'] = true;
                     }
                     // Validate multiple emails separated by commas
                     if (isset($field["multiple"])) {
                         // Removes spaces
                         $emails = str_replace(" ", "", $this->data[$field["name"]]);
                         // Array of emails
                         $emails = explode(",", $emails);
                         if (count($emails) > 1) {
                             $config['message'] = Yii::t('app', '{attribute} has a invalid email format: Please use a comma to separate multiple email addresses.');
                         }
                         // Validate only one email address
                         $emailValidator = new EmailValidator($config);
                         foreach ($emails as $email) {
                             if (!$emailValidator->validate($email, $error)) {
                                 $this->addError($field["name"], $field["label"], '', $error);
                             }
                         }
                     } else {
                         // Validate only one email address
                         $emailValidator = new EmailValidator($config);
                         if (!$emailValidator->validate($this->data[$field["name"]], $error)) {
                             $this->addError($field["name"], $field["label"], '', $error);
                         }
                     }
                 }
             }
             // Radio
             if ($key === "type" && $value === "radio") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && !empty($this->data[$field["name"]])) {
                     // If no values or if the received data does not match with the form data
                     if (empty($this->radioValues) || !in_array($this->data[$field["name"]], $this->radioValues)) {
                         $this->addError($field["name"], $field["groupLabel"], '', $invalidMessage);
                     }
                 }
             }
             // Checkbox
             if ($key === "type" && $value === "checkbox") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && !empty($this->data[$field["name"]])) {
                     // If no values or if the received data does not match with the form data
                     foreach ($this->data[$field["name"]] as $labelChecked) {
                         if (empty($this->checkboxValues) || !in_array($labelChecked, $this->checkboxValues)) {
                             $this->addError($field["name"], $field["groupLabel"], '', $invalidMessage);
                         }
                     }
                 }
             }
             // Select List
             if ($key === "tagName" && $value === "select") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && !empty($this->data[$field["name"]])) {
                     // If no labels or if the received data does not match with the form data
                     foreach ($this->data[$field["name"]] as $optionSelected) {
                         if (empty($this->optionValues) || !in_array($optionSelected, $this->optionValues)) {
                             $this->addError($field["name"], $field["label"], '', $invalidMessage);
                         }
                     }
                 }
             }
             // Number & Range
             if ($key === "type" && $value === "number" || $key === "type" && $value === "range") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // Config number validator
                     $config = [];
                     // Min Number Validation (Minimum value required)
                     if (isset($field["min"])) {
                         $config['min'] = $field["min"];
                     }
                     // Max Number Validation (Maximum value required)
                     if (isset($field["max"])) {
                         $config['max'] = $field["max"];
                     }
                     // Only Integer Validation (Whether the attribute value can only be an integer)
                     if (isset($field["data-integer-only"])) {
                         $config['integerOnly'] = true;
                     }
                     // Pattern to Validate only Integer Numbers (The regular expression for matching integers)
                     if (isset($field["data-integer-pattern"])) {
                         $config['integerPattern'] = $field["data-integer-pattern"];
                     }
                     // Pattern to Validate the Number (The regular expression for matching numbers)
                     if (isset($field["data-number-pattern"])) {
                         $config['numberPattern'] = $field["data-number-pattern"];
                     }
                     $numberValidator = new NumberValidator($config);
                     if (!$numberValidator->validate($this->data[$field["name"]], $error)) {
                         $this->addError($field["name"], $field["label"], '', $error);
                     }
                 }
             }
             // Date & DateTime & Time & Month & Week
             if ($key === "type" && $value === "date" || $key === "type" && $value === "datetime-local" || $key === "type" && $value === "time" || $key === "type" && $value === "month" || $key === "type" && $value === "week") {
                 // Only when the input value is not empty
                 if (isset($field["name"]) && trim($this->data[$field["name"]]) !== "") {
                     // DateValidator Configuration array
                     $config = [];
                     // Date Format by default
                     $format = "Y-m-d";
                     // Change Format
                     if ($value === "datetime-local") {
                         // DateTime Format
                         $format = "Y-m-d\\TH:i:s";
                     } elseif ($value === "time") {
                         // Time Format
                         $format = "i:s";
                     } elseif ($value === "month") {
                         // Month Format
                         $format = "Y-m";
                     } elseif ($value === "week") {
                         // First, validate by regular expression
                         $regexValidator = new RegularExpressionValidator(['pattern' => "/\\d{4}-W\\d{2}/"]);
                         if (!$regexValidator->validate($this->data[$field["name"]], $error)) {
                             $this->addError($field["name"], $field["label"], '', $error);
                         }
                         // Next, convert to date, to dateValidator (min / max)
                         if (isset($field["min"])) {
                             $config['tooSmall'] = Yii::t("app", "{attribute} must be no less than {weekMin}.", ['weekMin' => $field["min"]]);
                             $field["min"] = date("Y-m-d", strtotime($field["min"]));
                         }
                         if (isset($field["max"])) {
                             $config['tooBig'] = Yii::t("app", "{attribute} must be no greater than {weekMax}.", ['weekMax' => $field["max"]]);
                             $field["max"] = date("Y-m-d", strtotime($field["max"]));
                         }
                         $this->data[$field["name"]] = date("Y-m-d", strtotime($this->data[$field["name"]]));
                     }
                     // Add PHP format
                     $config['format'] = "php:" . $format;
                     // Add Min Date Validation (The value must be later than this option)
                     if (isset($field["min"])) {
                         $config['min'] = $field["min"];
                     }
                     // Add Max Date Validation (The value must be earlier than this option)
                     if (isset($field["max"])) {
                         $config['max'] = $field["max"];
                     }
                     $dateValidator = new DateValidator($config);
                     if (!$dateValidator->validate($this->data[$field["name"]], $error)) {
                         $this->addError($field["name"], $field["label"], '', $error);
                     }
                 }
             }
             // File
             if ($key === "type" && $value === "file") {
                 // Only when the $_FILES name value is not empty
                 if (isset($field["name"]) && isset($_FILES[$field["name"]]['name']) && !empty($_FILES[$field["name"]]['name'])) {
                     // Config FileValidator
                     $config = [];
                     // File type validation
                     // Note that you should enable fileinfo PHP extension.
                     if (isset($field["accept"]) && extension_loaded('fileinfo')) {
                         // Removes dots
                         $extensions = str_replace(".", "", $field["accept"]);
                         // Removes spaces
                         $extensions = str_replace(" ", "", $extensions);
                         $config['extensions'] = explode(",", $extensions);
                     }
                     // File Min Size validation
                     if (isset($field["data-min-size"])) {
                         // Removes dots
                         $config['minSize'] = (int) $field["data-min-size"];
                     }
                     // File Min Size validation
                     if (isset($field["data-max-size"])) {
                         // Removes dots
                         $config['maxSize'] = (int) $field["data-max-size"];
                     }
                     $file = UploadedFile::getInstanceByName($field["name"]);
                     $fileValidator = new FileValidator($config);
                     if (!$fileValidator->validate($file, $error)) {
                         $this->addError($field["name"], $field["label"], '', $error);
                     }
                 }
             }
         }
     }
 }