From 2280e8ea67f94e67f2c803e804fb1b8125b579b0 Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Wed, 15 Dec 2010 10:16:38 -0500 Subject: Added the regex_match Form Validation rule. Had to change how the rules are split so that no regex breaks the rule splitting. --- system/libraries/Form_validation.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'system/libraries/Form_validation.php') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index bf3689058..38f50fa41 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -339,7 +339,13 @@ class CI_Form_validation { } } - $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); + preg_match_all('/([a-zA-Z_-]*(\[.*\])?)\|?/i', $row['rules'], $matches); + + $rules = $matches[1]; + array_pop($rules); + unset($matches); + + $this->_execute($row, $rules, $this->_field_data[$field]['postdata']); } // Did we end up with any errors? @@ -576,7 +582,7 @@ class CI_Form_validation { // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + if (preg_match("/(.*?)\[(.*)\]/", $rule, $match)) { $rule = $match[1]; $param = $match[2]; @@ -888,6 +894,26 @@ class CI_Form_validation { // -------------------------------------------------------------------- + /** + * Performs a Regular Expression match test. + * + * @access public + * @param string + * @param regex + * @return bool + */ + function regex_match($str, $regex) + { + if ( ! preg_match($regex, $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Match one field to another * -- cgit v1.2.3-24-g4f1b From 5c561805bd9ae6a4ad5d202277c34a879617b683 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 5 Jan 2011 16:31:59 +0000 Subject: If the data is an array output them one at a time. E.g: form_input('name[]', set_value('name[]'); --- system/libraries/Form_validation.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system/libraries/Form_validation.php') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 38f50fa41..f45760024 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -736,6 +736,13 @@ class CI_Form_validation { return $default; } + // If the data is an array output them one at a time. + // E.g: form_input('name[]', set_value('name[]'); + if (is_array($this->_field_data[$field]['postdata'])) + { + return array_shift($this->_field_data[$field]['postdata']); + } + return $this->_field_data[$field]['postdata']; } -- cgit v1.2.3-24-g4f1b From c3828718925a0f1660cddadc95b63e14f7189faa Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 19 Jan 2011 12:31:47 +0000 Subject: Reverted regex validation while we re-think the implementation, and added ->input->is_cli_request(); --- system/libraries/Form_validation.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'system/libraries/Form_validation.php') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index f45760024..9fe76b5f2 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -171,7 +171,7 @@ class CI_Form_validation { } $this->_error_messages = array_merge($this->_error_messages, $lang); - + return $this; } @@ -191,7 +191,7 @@ class CI_Form_validation { { $this->_error_prefix = $prefix; $this->_error_suffix = $suffix; - + return $this; } @@ -339,13 +339,7 @@ class CI_Form_validation { } } - preg_match_all('/([a-zA-Z_-]*(\[.*\])?)\|?/i', $row['rules'], $matches); - - $rules = $matches[1]; - array_pop($rules); - unset($matches); - - $this->_execute($row, $rules, $this->_field_data[$field]['postdata']); + $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); } // Did we end up with any errors? @@ -742,7 +736,7 @@ class CI_Form_validation { { return array_shift($this->_field_data[$field]['postdata']); } - + return $this->_field_data[$field]['postdata']; } -- cgit v1.2.3-24-g4f1b From ef112c0830df4a31563351125888b0d522a1c965 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 7 Feb 2011 13:01:47 +0000 Subject: Added decimal, less_than and greater_than rules to the Form validation Class. --- system/libraries/Form_validation.php | 70 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 10 deletions(-) (limited to 'system/libraries/Form_validation.php') 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); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8761ef56b465a190489ed555c6a0ab58470bfc73 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:13:52 -0500 Subject: Uppercasing some stray lowercase keywords for code consistency --- system/libraries/Form_validation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Form_validation.php') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 745fb7c03..c6d7c2976 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1177,7 +1177,7 @@ class CI_Form_validation { { if ( ! is_numeric($str)) { - return false; + return FALSE; } return $str > $min; } @@ -1195,7 +1195,7 @@ class CI_Form_validation { { if ( ! is_numeric($str)) { - return false; + return FALSE; } return $str < $max; } -- cgit v1.2.3-24-g4f1b From 14287f3e81d4d717ff49e640d799c579e593f0c0 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:39:34 -0500 Subject: Whitespace cleanup in libraries/ --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Form_validation.php') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index c6d7c2976..adfd17db1 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1040,7 +1040,7 @@ class CI_Form_validation { return $this->valid_email(trim($str)); } - foreach(explode(',', $str) as $email) + foreach (explode(',', $str) as $email) { if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) { -- cgit v1.2.3-24-g4f1b