From ceaf887a7a849eab95b1bed1a837e2e3a1720c99 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Fri, 15 Jun 2012 11:56:24 +0200 Subject: some optimizations --- system/libraries/Form_validation.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 621316c4a..6d4446d0c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -998,14 +998,18 @@ class CI_Form_validation { */ public function min_length($str, $val) { - if (preg_match('/[^0-9]/', $val)) + if ( ! is_numeric($val)) { return FALSE; } + else + { + $val = (int) $val; + } return (MB_ENABLED === TRUE) - ? (intval($val) <= mb_strlen($str)) - : (intval($val) <= strlen($str)); + ? ($val <= mb_strlen($str)) + : ($val <= strlen($str)); } // -------------------------------------------------------------------- @@ -1019,14 +1023,18 @@ class CI_Form_validation { */ public function max_length($str, $val) { - if (preg_match('/[^0-9]/', $val)) + if ( ! is_numeric($val)) { return FALSE; } + else + { + $val = (int) $val; + } return (MB_ENABLED === TRUE) - ? (intval($val) >= mb_strlen($str)) - : (intval($val) >= strlen($str)); + ? ($val >= mb_strlen($str)) + : ($val >= strlen($str)); } // -------------------------------------------------------------------- @@ -1040,14 +1048,18 @@ class CI_Form_validation { */ public function exact_length($str, $val) { - if (preg_match('/[^0-9]/', $val)) + if ( ! is_numeric($val)) { return FALSE; } + else + { + $val = (int) $val; + } return (MB_ENABLED === TRUE) - ? (mb_strlen($str) === intval($val)) - : (strlen($str) === intval($val)); + ? (mb_strlen($str) === $val) + : (strlen($str) === $val); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b