You are here

function uc_numeric_validate in Ubercart 5

File

uc_store/uc_store.module, line 2607
Contains global Ubercart functions and store administration functionality.

Code

function uc_numeric_validate($form, $sign = 0) {
  $error = t('You must enter a number.');
  switch ($sign) {
    case -1:
      $error = t('You must enter a negative number.');
      break;
    case 1:
      $error = t('You must enter a positive number.');
      break;
  }

  // Allow an empty field to be cast to 0
  if (empty($form['#value']) || is_numeric($form['#value'])) {
    if ($form['#value'] <= 0 && $sign == 1 || $form['#value'] >= 0 && $sign == -1) {
      form_error($form, $error);
    }
  }
  else {
    form_error($form, $error);
  }
}