summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorDan Horrigan <dan@dhorrigan.com>2010-12-15 16:16:38 +0100
committerDan Horrigan <dan@dhorrigan.com>2010-12-15 16:16:38 +0100
commit2280e8ea67f94e67f2c803e804fb1b8125b579b0 (patch)
tree174f127e3e8858a7620b05557cb34b77c5afc4b7 /system
parent65d603e03d3befd6e4f13361c78ab454ea57ba70 (diff)
Added the regex_match Form Validation rule. Had to change how the rules are split so that no regex breaks the rule splitting.
Diffstat (limited to 'system')
-rw-r--r--system/language/english/form_validation_lang.php1
-rw-r--r--system/libraries/Form_validation.php30
2 files changed, 29 insertions, 2 deletions
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index 99ed70a5c..b01885091 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -15,6 +15,7 @@ $lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters,
$lang['numeric'] = "The %s field must contain only numbers.";
$lang['is_numeric'] = "The %s field must contain only numeric characters.";
$lang['integer'] = "The %s field must contain an integer.";
+$lang['regex_match'] = "The %s field is not in the correct format.";
$lang['matches'] = "The %s field does not match the %s field.";
$lang['is_natural'] = "The %s field must contain only positive numbers.";
$lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
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];
@@ -889,6 +895,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
*
* @access public