I've been looking in other similar posts and the problem seemed to be an unescaped slash. However I'm escaping them.
This is how the string should look:
23/12/2012
and this is how I'm declaring the validation rule:
regex_match[/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)[0-9]{2}$/]
The ending delimiter is there, and the two inbetween slashes for the date are being escaped with a backslash. I've also tried this which is slightly different, but I get the same error:
regex_match[/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$/]
Where's the error?
EDIT:
Following your advice, I've tried using a callback function. This is the declaration, which is located within the controller class in which the form validation is being executed:
function mach_date($date) {
/* DEBUG */ echo 'Here I am!'; exit; // execution should stop here displaying the echo
return (bool)preg_match('/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$/', $date);
}
Validation rules in application/config/form_validation.php:
$config = array(
// other validation groups.....,
'articles' => array(
// other validated fields.....,
array(
'field' => 'date_p',
'label' => 'Publishing date',
'rules' => 'callback_match_date'
)
)
);
When you set the validation rules you separate them with a | so the |'s in your regex is causing the validation rule to split at those and that is causing the error. Discussion here on the issue. It seems it's a limitation or bug in codeigniter. You can test it out by running a regex with and without |'s and see if the usage of pipes will cause an error. If that is the case then you may have to validate by regex by other means, maybe use a callback function as detailed on this page where your function will do a preg_match using the regex which needs to be inside the function of course and then return true/false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With