New form_validation rule: 'differs'
Added new validation rule 'differs'. It checks if the value of a field differs from the value of another field.
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index cf1b3b5..6ff0cc2 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -42,6 +42,7 @@
$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['differs'] = 'The %s field must differ from the %s field.';
$lang['is_unique'] = 'The %s field must contain a unique value.';
$lang['is_natural'] = 'The %s field must only contain digits.';
$lang['is_natural_no_zero'] = 'The %s field must only contain digits and must be greater than zero.';
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index fccc12a..6db5bb4 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -971,6 +971,19 @@
// --------------------------------------------------------------------
/**
+ * Differs from another field
+ *
+ * @param string
+ * @param string field
+ * @return bool
+ */
+ public function differs($str, $field)
+ {
+ return ! (isset($this->_field_data[$field]) && $this->_field_data[$field]['postdata'] === $str);
+ }
+
+ // --------------------------------------------------------------------
+ /**
* Is Unique
*
* Check if the input value doesn't already exist