1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Closed Suggestions' started by digitalpoint, Nov 28, 2011.

  1. digitalpoint

    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:
    XenForo_Input::stripNumbers true;
    then in the case of a NUM type, it could be something like:
    case self::NUM:
        if (
    $this->stripNumbers$data preg_replace("#[^0-9\.]#"''$data);
    $data strval($data) + 0;
    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. :)
    qpa and Bob like this.
  2. Kier

    Kier XenForo Developer Staff Member

    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.
    digitalpoint and qpa like this.
  3. digitalpoint

    digitalpoint Well-Known Member

    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". :)

Share This Page