You are here

function masked_input_validate_numeric in Masked Input 7.2

Element validation callback for masked_input elements that require values to be stored as "numeric"

1 string reference to 'masked_input_validate_numeric'
masked_input_field_widget_form in ./masked_input.module
Implements hook_field_widget_form().

File

./masked_input.module, line 214
Provides a form element, Field widget, and simple API for using the Masked Input jQuery plugin.

Code

function masked_input_validate_numeric($element, &$form_state) {
  $existing = NULL;
  $value = drupal_array_get_nested_value($form_state['values'], $element['#parents'], $existing);

  // If the value in question cannot be recognized as being numeric, we strip
  // away everything except numbers and decimals.
  if (!is_numeric($value) && $existing) {
    $clean_value = preg_replace('/[^0-9\\.]/u', '', $value);
    form_set_value($element, $clean_value, $form_state);
  }
}