hook_field_validate($entity_type, $entity, $field, $instance, $langcode, &$items, &$errors)Define custom validate behavior for this module's field types.
$entity_type The type of $entity.
$entity The entity for the operation.
$field The field structure for the operation.
$instance The instance structure for $field on $entity's bundle.
$langcode The language associated to $items.
$items $entity->{$field['field_name']}[$langcode], or an empty array if unset.
$errors The array of errors, keyed by field name and by value delta, that have already been reported for the entity. The function should add its errors to this array. Each error is an associative array, with the following keys and values:
modules/field/field.api.php, line 376
<?php
function hook_field_validate($entity_type, $entity, $field, $instance, $langcode, &$items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['value'])) {
if (!empty($field['settings']['max_length']) && drupal_strlen($item['value']) > $field['settings']['max_length']) {
$errors[$field['field_name']][$delta][] = array(
'error' => 'text_max_length',
'message' => t('%name: the value may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])),
);
}
}
}
}
?>