You are here

function number_float_validate in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 modules/number/number.module \number_float_validate()
  2. 6.2 modules/number/number.module \number_float_validate()

FAPI validation of an individual float element.

1 string reference to 'number_float_validate'
number_process in modules/number/number.module
Process an individual element.

File

modules/number/number.module, line 457
Defines numeric field types.

Code

function number_float_validate($element, &$form_state) {
  $field_key = $element['#columns'][0];
  $value = $element['#value'][$field_key];
  if ($element[$field_key]['#required'] || !empty($value)) {
    $start = $value;
    $value = preg_replace('@[^-0-9\\.]@', '', $value);
    if ($start != $value) {

      // No reason to make this an error, just need to inform user what has changed.
      drupal_set_message(t('Only numbers and decimals are allowed in %field. %start was changed to %value.', array(
        '%field' => t($element[$field_key]['#title']),
        '%start' => $start,
        '%value' => $value,
      )));
    }
    form_set_value($element[$field_key], $value, $form_state);
  }
}