Form element validate handler for taxonomy term autocomplete element.
function taxonomy_autocomplete_validate($element, &$form_state) {
// Split the values into an array.
// @see Drupal\taxonomy\Plugin\field\widget\TaxonomyAutocompleteWidget:massageFormValues()
$typed_terms = array();
if ($tags = $element['#value']) {
$typed_terms = drupal_explode_tags($tags);
}
form_set_value($element, $typed_terms, $form_state);
}