$attribute; $pattern = '/^\d*(\.\d*)*$/'; if ($value && !preg_match($pattern, $value)) { $model->addError($attribute, "{$model->getAttributeLabel($attribute)}格式不正确。"); } } }