Unique field value per multivalued field collection Field collection Config (multi value)

Field1---Name -Autocomplete (single value) (Entity Reference)
Field2---Score - Computed field.


Example Values for field collections

Field collection [0]
------Bill (1112)- where 1112 is nid
------Score - some value will be generated depends on 1112

Field collection [1]
------Roger (1345)- where 1345 is nid
------Score - some value will be generated depends on 1345

Field collection [2]
------Roger (1467)- where 1467 is nid
------Score - some value will be generated depends on 1467
..
..
Field collection [n]
------Maddy (1652)- where 1652 is nid
------Score - some value will be generated depends on 1652


From above config how to make field Name's value should not hold the duplicate value for field collection ie Bill should not be applied again.
There is a module called https://drupal.org/project/unique_field which forces field's value to be unique per content type or per all node, but not per field.
In above case somehow(that what is required) if we make per field then also it could only applied to Name field which is inside field collection rather than field collection itself. Right?
I had to do this the other day and found it easiest with a custom validation function.

Using hook_form_alter add a new validation function:

function YOUR_MODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  //drupal_set_message("Form ID is : " . $form_id);
  switch($form_id) {
    case 'YOUR_FORM_ID':
      //dpm($form);
      $form['#validate'][] = 'validate_unique_field_collection_names';
      break;
  }
}


And then in your new validation function:

function validate_unique_field_collection_names($form, &amp;$form_state) {
  $used_ids = array();
  foreach($form_state['values']['field_people_collection'][LANGUAGE_NONE] as $k =&gt; $item) {
    if($k === 'add_more') continue; // skip loop if key is add_more
    $user_target_id = $item['field_name'][LANGUAGE_NONE][0]['target_id'];
    if(in_array($user_target_id, $used_ids)) { // check if UID is in used array
      form_set_error('field_people_collection]['.LANGUAGE_NONE.']['.$k.'][field_name', t('Names must be unique.')); // if it is set an error
    } else {
      $used_ids[] = $user_target_id; // else add it into the used array
    }
  }
}