Ignore:
Timestamp:
Jul 27, 2015 7:56:08 AM (9 years ago)
Author:
anonymous
Message:

Improved module maker validation output. Allow disabling cache at run time for ACL. Added ACL getList() method. Improved ACL CLI listing. Fixed app boomerang array initialization. Now retaining identical boomerang URLs if the key is different. Added a maximum boomerang time. Added a way to disable cache per request through a query string. Added validator isDecimal() method. Added disableSelectOptions() HTML method. Added getGravatarURL() method. Change how navigation page array is managed. Updated navigation currentPage() method to test an array of URLs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Validator.inc.php

    r523 r534  
    120120     *
    121121     * @param  string $val The input data to validate.
     122     * @param  bool $negative_ok  If the value can be unsigned.
    122123     * @return bool   true if value is a float
    123124     */
     
    126127        $pattern = $negative_ok ? '/^-?[[:digit:]]*(?:\.?[[:digit:]]+)$/' : '/^[[:digit:]]*(?:\.?[[:digit:]]+)$/';
    127128        return '' == trim((string)$val) || (is_numeric($val) && preg_match($pattern, $val));
     129    }
     130
     131    /**
     132     * Check whether input is a Decimal or Fixed type. Check values to be stored in mysql decimal, numeric, num, or fixed types.
     133     * Note: some integers and floats will also pass this test.
     134     * https://dev.mysql.com/doc/refman/5.5/en/fixed-point-types.html
     135     *
     136     * @param  string $val The input data to validate.
     137     * @param  bool $negative_ok  If the value can be unsigned.
     138     * @param  int  $max    Total max number of digits (for mysql max is 65).
     139     * @param  int  $dec    Total max number of digits after the decimal place (for mysql max is 30).
     140     * @return bool   true if value is a float
     141     */
     142    static public function isDecimal($val, $negative_ok=false, $max=10, $dec=2)
     143    {
     144        if ('' == trim((string)$val)) {
     145            return true;
     146        }
     147        if (!$negative_ok && is_numeric($val) && $val < 0) {
     148            return false;
     149        }
     150        // Get the length of the part after any decimal point, or zero.
     151        $num_parts = explode('.', $val);
     152        $dec_count = sizeof($num_parts) <= 1 ? 0 : mb_strlen(end($num_parts));
     153        // Must be numeric, total digits <= $max, dec digits <= $dec.
     154        return is_numeric($val) && mb_strlen(str_replace(['-', '.'], '', $val)) <= $max && $dec_count <= $dec;
    128155    }
    129156
Note: See TracChangeset for help on using the changeset viewer.