You are here

function number_decimal_validate in Content Construction Kit (CCK) 6

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

FAPI validation of an individual decimal element.

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

File

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

Code

function number_decimal_validate($element, &$form_state) {
  $field_key = $element['#columns'][0];
  $value = $element['#value'][$field_key];
  if ($element[$field_key]['#required'] || !empty($value)) {
    $start = $value;
    $value = str_replace($element['#decimal'], '.', $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 the decimal character (%decimal) are allowed in %field. %start was changed to %value.', array(
        '%decimal' => $element['#decimal'],
        '%field' => t($element[$field_key]['#title']),
        '%start' => $start,
        '%value' => $value,
      )));
    }
    $value = round($value, $element['#scale']);
    form_set_value($element[$field_key], $value, $form_state);
  }
}