Lack of interest XenForo_Input::_doClean() could be a little smarter

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

digitalpoint

Well-known member
It would be nice if floats, ints and nums would strip out non-numeric characters first.

For example, if a user enters a number as "$12,345.67", we end up with "0" as the integer. If they enter it as "12,345.67", the resulting integer is "12".

I don't think it would be worthwhile to *always* do a preg_replace first, but in the cases where you know it's a free-form field that the user is supposed to enter a number, it would be nice to be able to set a flag within the XenForo_Input class to do it...

Something like:
PHP:
XenForo_Input::stripNumbers = true;
then in the case of a NUM type, it could be something like:
PHP:
case self::NUM:
	if ($this->stripNumbers) $data = preg_replace("#[^0-9\.]#", '', $data);
	$data = strval($data) + 0;
break;

Now obviously you could take the input as a string and do it all yourself every time you need to, but the Input class is supposed to make it so you don't need to do that... Just would be nice. :)
 
Upvote 2
This suggestion has been closed. Votes are no longer accepted.
It would need to be a little more complex than that, as the thousands separator and decimal point vary with language: 1,234.56 to a German writer would be 1.234,56.

Still, it might be something we could work in there somehow.
 
Could probably detect the preferred language of the end user automatically via the Zend_Locale class (which I believe keys on the end-users preferred language in the HTTP_ACCEPT_LANGUAGE header). Not a huge deal... just would be nice to not have users crying after the fact they they entered a number as 1,234.45, and they ended up with "1". :)
 
Top Bottom