function number_field_validate

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

drupal/core/modules/number/number.module, line 130
Defines numeric field types.

Code

function number_field_validate(EntityInterface $entity = NULL, $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'],
          )),
        );
      }
    }
  }
}