summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-02-07 14:01:47 +0100
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-02-07 14:01:47 +0100
commitef112c0830df4a31563351125888b0d522a1c965 (patch)
tree3552458b818c72d48af88784c59e0dd04a9d7a00 /system
parent287763b919d2f1522cf4e6e39c0d33a957ff0538 (diff)
Added decimal, less_than and greater_than rules to the Form validation Class.
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Form_validation.php70
1 files changed, 60 insertions, 10 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index fc5b82ee3..745fb7c03 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -138,14 +138,14 @@ class CI_Form_validation {
// Build our master array
$this->_field_data[$field] = array(
- 'field' => $field,
- 'label' => $label,
- 'rules' => $rules,
- 'is_array' => $is_array,
- 'keys' => $indexes,
- 'postdata' => NULL,
- 'error' => ''
- );
+ 'field' => $field,
+ 'label' => $label,
+ 'rules' => $rules,
+ 'is_array' => $is_array,
+ 'keys' => $indexes,
+ 'postdata' => NULL,
+ 'error' => ''
+ );
return $this;
}
@@ -1147,7 +1147,57 @@ class CI_Form_validation {
*/
function integer($str)
{
- return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str);
+ return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Decimal number
+ *
+ * @access public
+ * @param string
+ * @return bool
+ */
+ function decimal($str)
+ {
+ return (bool) preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $str);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Greather than
+ *
+ * @access public
+ * @param string
+ * @return bool
+ */
+ function greater_than($str, $min)
+ {
+ if ( ! is_numeric($str))
+ {
+ return false;
+ }
+ return $str > $min;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Less than
+ *
+ * @access public
+ * @param string
+ * @return bool
+ */
+ function less_than($str, $max)
+ {
+ if ( ! is_numeric($str))
+ {
+ return false;
+ }
+ return $str < $max;
}
// --------------------------------------------------------------------
@@ -1161,7 +1211,7 @@ class CI_Form_validation {
*/
function is_natural($str)
{
- return (bool)preg_match( '/^[0-9]+$/', $str);
+ return (bool) preg_match( '/^[0-9]+$/', $str);
}
// --------------------------------------------------------------------