You are here

function _webform_numeric_check_data in Webform Validation 7

Same name and namespace in other branches
  1. 6 webform_validation.validators.inc \_webform_numeric_check_data()

Helper function to check numeric data.

Process the numeric value validation range that was provided in the numeric validator options.

1 call to _webform_numeric_check_data()
webform_validation_webform_validation_validate in ./webform_validation.validators.inc
Implements hook_webform_validation_validate().

File

./webform_validation.validators.inc, line 1174
Provides validation functionality and hooks.

Code

function _webform_numeric_check_data($data) {
  $range = array(
    'min' => NULL,
    'max' => NULL,
  );

  // If no value was specified, don't validate.
  if ($data == '') {
    return $range;
  }

  // If only one numeric value was specified, this is the min value.
  if (is_numeric($data)) {
    $range['min'] = (double) $data;
  }
  if (strpos($data, '|') !== FALSE) {
    list($min, $max) = explode('|', $data);
    if ($min != '' && is_numeric($min)) {
      $range['min'] = (double) $min;
    }
    if ($max != '' && is_numeric($max)) {
      $range['max'] = (double) $max;
    }
  }
  return $range;
}