You are here

function value_is_integer in Value is 7

Checks for integer (non floating point number).

File

./value_is.module, line 257
All the element validators for #element_validate.

Code

function value_is_integer($element, &$form_state, $form) {
  $value = $element['#value'];
  if ('' != $value) {

    // Not even close.
    if (!_value_is_integer($value)) {
      return form_error($element, t('Only numbers are allowed in %field.', array(
        '%field' => $element['#title'],
      )));
    }

    // Too low.
    if (isset($element['#min']) && $value < $element['#min']) {
      return form_error($element, t('%name: the value may be no less than %min.', array(
        '%name' => $element['#title'],
        '%min' => $element['#min'],
      )));
    }

    // Too high.
    if (isset($element['#max']) && $value > $element['#max']) {
      return form_error($element, t('%name: the value may be no greater than %max.', array(
        '%name' => $element['#title'],
        '%max' => $element['#max'],
      )));
    }

    // Cast input value to an Int.
    form_set_value($element, (int) $value, $form_state);
  }
}