You are here

function uc_attribute_option_form_validate in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.admin.inc \uc_attribute_option_form_validate()
  2. 7.3 uc_attribute/uc_attribute.admin.inc \uc_attribute_option_form_validate()

Validate number formats.

File

uc_attribute/uc_attribute.module, line 667

Code

function uc_attribute_option_form_validate($form_id, $form_values) {
  $pattern = '/^-?\\d*(\\.\\d*)?$/';
  $price_error = t('This must be in a valid number format. No commas and only one decimal point.');
  if (!is_numeric($form_values['cost']['#value']) && !preg_match($pattern, $form_values['cost']['#value'])) {
    form_set_error('cost', $price_error);
  }
  if (!is_numeric($form_values['price']['#value']) && !preg_match($pattern, $form_values['price']['#value'])) {
    form_set_error('price', $price_error);
  }
  if (!is_numeric($form_values['weight']['#value']) && !preg_match($pattern, $form_values['weight']['#value'])) {
    form_set_error('weight', $price_error);
  }
}