Welcome Guest, Not a member yet? Register   Sign In
Form validation with Greater Than won't work with international currencies (comma separated decimal numbers)
#4

[eluser]landitus[/eluser]
I think extending the library would be nicer. Unfortunately I am not fluent enough in REGEX to do so. But I was able to do a minor hack to make the validation work with commas. Before validation I do a string replace to find the dot and turn it into a comma.

This is MY_Form_validation.php file
Code:
/**
  * Money
  *
  * @access public
  * @param string
  * @return bool
  */
public function is_money($input) {
     return (bool) preg_match('/^[0-9]+(\,[0-9]{0,2})?$/', $input);
}

    
/**
  * Greather than Money
  *
  * @access public
  * @param string
  * @return bool
  */
function greater_than_money($str, $min)
{
  $str = str_replace(",", ".", $str);
  if ( ! is_numeric($str))
  {
   return FALSE;
  }
  return $str > $min;
}


Messages In This Thread
Form validation with Greater Than won't work with international currencies (comma separated decimal numbers) - by El Forum - 04-26-2012, 05:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB