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:
then in the case of a NUM type, it could be something like:
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.
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;
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