You are here

function number_float_validate in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 6 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 508
Defines numeric field types.

Code

function number_float_validate($element, &$form_state) {
  $field_name = $element['#field_name'];
  $type_name = $element['#type_name'];
  $field = content_fields($field_name, $type_name);
  $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) {
      $error_field = implode('][', $element['#parents']) . '][' . $field_key;
      form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array(
        '%field' => t($field['widget']['label']),
      )));
    }
    else {
      form_set_value($element[$field_key], $value, $form_state);
    }
  }
}