How to override code of module in custom module? I am using Content Taxonomy module and trying to override some code, when I tried to modify in my custom module then the module functions also keeps running. And by modifying module file my purpose get solved but is there any way to do it in my custom module, please suggest:

CODE NEED TO MODIFIED:

/**
 * Form element validate handler for taxonomy term autocomplete element, which denies any new terms.
 */
function content_taxonomy_autocomplete_validate_deny_new_terms($element, &amp;$form_state, $form) {
  $values = $form_state['values'];
  foreach ($element['#array_parents'] as $parent) {
    $values = $values[$parent];
  }
  foreach ($values as $delta =&gt; $value) {
    if ($value['tid'] == 'autocreate') {
      form_error($element, t('%name: new terms are not allowed. Please choose from the given list.', array('%name' =&gt; $element['#title'])));
    }
  }
} 


DOING LIKE BELOW:

function custom_overrides_field_attach_form($entity_type, $entity, &amp;$form, &amp;$form_state, $langcode) {
  // Add validation function to taxonomy_autocompletes, if necessary.
  $instances = field_info_instances($form['#entity_type'], $form['#bundle']);
  foreach ($instances as $instance) {
    if (($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy') 
      &amp;&amp; isset($form[$instance['field_name']]) 
      &amp;&amp; isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'])) {

      // Use the language that is used in this form (which doesn't necessarily
      // be the default language in $langcode).
      $lang_key = $form[$instance['field_name']]['#language'];
      if ($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'] == 'moderate') {
        $form[$instance['field_name']][$lang_key]['#element_validate'][] = 'content_taxonomy_autocomplete_validate_moderate_new_terms';
      }
      else if ($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'] == 'deny') {
        $form[$instance['field_name']][$lang_key]['#element_validate'][] = 'custom_content_taxonomy_autocomplete_validate_deny_new_terms';
        var_dump($form[$instance['field_name']]);
      }
    }
  }
}

/**
 * Form element validate handler for taxonomy term autocomplete element, which denies any new terms.
 */
function custom_content_taxonomy_autocomplete_validate_deny_new_terms($element, &amp;$form_state, $form) {
  global $user;
       if($element['#title'] == "Topic"){
          if (!$user-&gt;uid) {
                $values = $form_state['values'];
                foreach ($element['#array_parents'] as $parent) {
                  $values = $values[$parent];
                }
                foreach ($values as $delta =&gt; $value) {
                  if ($value['tid'] == 'autocreate') {
                     form_error($element, t('%name: new terms are not allowed. Please choose from the given list.', array('%name' =&gt; $element['#title'])));
                  }
                }
            }
      }else{
            $values = $form_state['values'];
            foreach ($element['#array_parents'] as $parent) {
              $values = $values[$parent];
            }
            foreach ($values as $delta =&gt; $value) {
              if ($value['tid'] == 'autocreate') {
                form_error($element, t('%name: new terms are not allowed. Please choose from the given list.', array('%name' =&gt; $element['#title'])));
              }
            }
      }
 }


By Doing this now I have my custom validator running and my custom module weight is 1000 and contrib module weight is 0 but still its not working because I think second validator function as shown below in output of var_dump need to be unset by some way:

'#element_validate' =&gt; 
        array (size=3)
          0 =&gt; string 'taxonomy_autocomplete_validate' (length=30)
          1 =&gt; string 'content_taxonomy_autocomplete_validate_deny_new_terms' (length=53)
          2 =&gt; string 'custom_content_taxonomy_autocomplete_validate_deny_new_terms' (length=60)
You can use  hook_field_attach_form(). function much like it has been done in content_taxonomy_autocomplete module and replace the validate function to the one you want.

function MODULENAME_field_attach_form($entity_type, $entity, &amp;$form, &amp;$form_state, $langcode) {
 // Add validation function to taxonomy_autocompletes, if necessary.
  $instances = field_info_instances($form['#entity_type'], $form['#bundle']);
  foreach ($instances as $instance) {
    if (($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy') 
      &amp;&amp; isset($form[$instance['field_name']]) 
      &amp;&amp; isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'])) {

      // Use the language that is used in this form (which doesn't necessarily
      // be the default language in $langcode).
      $lang_key = $form[$instance['field_name']]['#language'];
      if ($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'] == 'moderate') {
        $form[$instance['field_name']][$lang_key]['#element_validate'][] = 'content_taxonomy_autocomplete_validate_moderate_new_terms';
      }
      else if ($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'] == 'deny') {
        $form[$instance['field_name']][$lang_key]['#element_validate'][] = 'YOUR_NEW_VALIDATOR_NAME';
      }
    }
  }

}


// add your validater function here