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

[eluser]CroNiX[/eluser]
You could create a callback and convert the number to a float and then do the comparison.
Haven't tested this, but the original conversion formula was found on php.net
Code:
public function greater_than_intl($str, $max)
{
  if (strpos($str, '.') !== FALSE && strpos($str, ',') !== FALSE && strpos($str, '.') < strpos($str, ','))
  {
    $str = str_replace('.', '',$str);
    $str = strtr($str,',', '.');          
  }
  else
  {
    $str = str_replace(',', '', $str);          
  }
      
  $str = float($str);

  $this->form_validation->set_message('greater_than_intl', 'The %s field must be greater than ' . $max);

  return ($str > $max);
}


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



Theme © iAndrew 2016 - Forum software by © MyBB