function number_field_validate in Drupal 7
Implements hook_field_validate().
Possible error codes:
- 'number_min': The value is less than the allowed minimum value.
- 'number_max': The value is greater than the allowed maximum value.
File
- modules/
field/ modules/ number/ number.module, line 135 - Defines numeric field types.
Code
function number_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if ($item['value'] != '') {
if (is_numeric($instance['settings']['min']) && $item['value'] < $instance['settings']['min']) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'number_min',
'message' => t('%name: the value may be no less than %min.', array(
'%name' => $instance['label'],
'%min' => $instance['settings']['min'],
)),
);
}
if (is_numeric($instance['settings']['max']) && $item['value'] > $instance['settings']['max']) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'number_max',
'message' => t('%name: the value may be no greater than %max.', array(
'%name' => $instance['label'],
'%max' => $instance['settings']['max'],
)),
);
}
}
}
}