Limit the number of uploads per image field depending of role I need a hook (or something similar) where I can set the number of image uploads depending of the role of the user.

In the settings of the field there is no way to set the maximum number of values users can enter, just one value for all roles. For example, for role #1 I want the users can upload just 3 images, for role #2 just 5 images.

I tried several ways but none worked. I tried using #element_validate but the validation never worked.

Is there some way to do that? I forgot to mention is for Drupal 7.
Solution1 Limit on the form:

function &lt;module&gt;_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'center_node_form') {
    global $user;
    // Only allow to upload 2 images for role = staff
    if (in_array('staff', $user-&gt;roles)) {
      $center_image_limit = 2;
      $form['#field_info']['field_center_image']['multiple'] = $center_image_limit;
      $i = 1;
      foreach ($form['field_center_image'] as $key =&gt; $value) {
        if (is_numeric($key)) {
          if ($i &gt; $center_image_limit) {
            unset($form['field_center_image'][$key]);
          }
          $i++;
        }
      }
    }
  }
}


Source: DRUPAL – LIMIT THE NUMBER OF VALUES OF A CONTENT TYPE FIELD BY ROLE @ 1

Solution2 Limit in validation:

function &lt;module&gt;_form_alter(&amp;$form, &amp;$form_state, $form_id) {  
  if ($form_id == 'center_node_form') {
    // Add the extra validation
    array_unshift($form['#validate'], '&lt;module&gt;_addtional_validate');
  }
}

function &lt;module&gt;_addtional_validate($form, $form_state) {
  $count = 0;
  foreach($form_state['values']['field_center_video'] as $video) {
    if (!empty($video['value'])) {
      $count++;
    }
  }

  global $user;
  // Only allow to upload 2 videos for role = staff
  if (in_array('staff', $user-&gt;roles)) {
    if ($count &gt; 2) {
      form_set_error('field_center_video', t('You cannot upload more than 2 videos'));
    }
  }
}


Source: DRUPAL – LIMIT THE NUMBER OF VALUES OF A CONTENT TYPE FIELD BY ROLE @ 2