private function validate($fields)
 {
     $errors = array();
     $formats = array('PHONE' => array("/^\\+7 \\([0-9]{3}\\) [0-9]{3} [0-9]{2} [0-9]{2}\$/"), 'EMAIL' => array("/^[a-zA-Z0-9.\\-_]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\$/"));
     foreach ($fields as $field) {
         if (isset($field['required']) && $field['required'] && (!isset($field['value']) || !$field['value'])) {
             $errors[$field['name']] = sprintf(Localization::getMessage('field_is_required'), Localization::getMessage($field['label']));
         }
         if (isset($field['format']) && $field['format'] && $field['value'] && isset($formats[$field['format']])) {
             $valid = false;
             foreach ($formats[$field['format']] as $format) {
                 if (preg_match($format, $field['value'])) {
                     $valid = true;
                 }
             }
             if (!$valid) {
                 $errors[$field['name']] = sprintf(Localization::getMessage('field_is_invalid'), Localization::getMessage($field['label']));
             }
         }
         if (isset($field['maxlength']) && $field['maxlength'] && $field['value']) {
             if (mb_strlen($field['value']) > $field['maxlength']) {
                 $errors[$field['name']] = sprintf(Localization::getMessage('field_is_too_long'), Localization::getMessage($field['label']), $field['maxlength']);
             }
         }
     }
     return $errors;
 }