Added third option to determine if regex needs to match or not match.

Also fixed a bug where errors were overwriting eachother
This commit is contained in:
Josh Sherman 2013-09-08 14:31:55 -04:00
parent 94a9e08661
commit ae188a82a6
3 changed files with 10 additions and 10 deletions

View file

@ -357,7 +357,7 @@ class Controller extends Object
} }
// Validates the hash if applicable // Validates the hash if applicable
if ($module->hash !== false) if ($valid_request === true && $module->hash !== false)
{ {
if (isset($_REQUEST['security_hash'])) if (isset($_REQUEST['security_hash']))
{ {
@ -386,7 +386,7 @@ class Controller extends Object
$valid_form_input = true; $valid_form_input = true;
if ($module->validate !== false) if ($valid_request === true && $valid_security_hash === true && $module->validate !== false)
{ {
$validation_errors = $module->__validate(); $validation_errors = $module->__validate();

View file

@ -425,13 +425,13 @@ class Module extends Object
// {{{ Checks using preg_match() // {{{ Checks using preg_match()
case 'regex': case 'regex':
if (count($rule) < 2) if (count($rule) < 3)
{ {
throw new Exception('Invalid validation rule, expected: "regex:string".'); throw new Exception('Invalid validation rule, expected: "regex:is|not:string".');
} }
else else
{ {
if (preg_match($rule[1], $value)) if ((strtolower($rule[1]) == 'not' && !preg_match($rule[2], $value)) || preg_match($rule[2], $value))
{ {
$errors[] = $message; $errors[] = $message;
} }

10
jar.php
View file

@ -1519,7 +1519,7 @@ class Controller extends Object
} }
// Validates the hash if applicable // Validates the hash if applicable
if ($module->hash !== false) if ($valid_request === true && $module->hash !== false)
{ {
if (isset($_REQUEST['security_hash'])) if (isset($_REQUEST['security_hash']))
{ {
@ -1548,7 +1548,7 @@ class Controller extends Object
$valid_form_input = true; $valid_form_input = true;
if ($module->validate !== false) if ($valid_request === true && $valid_security_hash === true && $module->validate !== false)
{ {
$validation_errors = $module->__validate(); $validation_errors = $module->__validate();
@ -6569,13 +6569,13 @@ class Module extends Object
// {{{ Checks using preg_match() // {{{ Checks using preg_match()
case 'regex': case 'regex':
if (count($rule) < 2) if (count($rule) < 3)
{ {
throw new Exception('Invalid validation rule, expected: "regex:string".'); throw new Exception('Invalid validation rule, expected: "regex:is|not:string".');
} }
else else
{ {
if (preg_match($rule[1], $value)) if ((strtolower($rule[1]) == 'not' && !preg_match($rule[2], $value)) || preg_match($rule[2], $value))
{ {
$errors[] = $message; $errors[] = $message;
} }