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