[eluser]Lucas3677[/eluser]
So I figured it out. The problem was that CodeIgniter uses | as the delimiter when it explode()s the rules into an array. Another issue I had later on was that when searching for the parameter, CodeIgniter uses the lazy .*? search so when I did "[12]{1}" the ] was being read as the end of the parameter. Here is the solution for your reference:
Code:
function regex($str, $regex)
{
$regex = str_replace('#OR#', '|', $regex);
$regex = str_replace('#OS#', '[', $regex);
$regex = str_replace('#CS#', ']', $regex);
if (preg_match($regex, $str, $matches))
{
return TRUE;
}
else
{
$this->set_message('regex', 'The %s field has an incorrect value.');
return FALSE;
}
}
Code:
$rules['oneortwo'] = 'required|callback_regex[/^(1#OR#2)$/i]';