Skip to content
Advertisement

Codeigniter is giving me an error called “Disallowed Key Characters.”

I have a input with name=”exam[A+]”. I have figured out that when I called $this->input->post("exam") it is giving me an error called “Disallowed Key Characters”. I want to add + sign in my key characters. Here is the code in the system file.

function _clean_input_keys($str)
    {
        if ( ! preg_match("/^[a-z0-9:_/-]+$/i", $str))
        {
            exit('Disallowed Key Characters.');
        }

        // Clean UTF-8 if supported
        if (UTF8_ENABLED === TRUE)
        {
            $str = $this->uni->clean_string($str);
        }

        return $str;
    }

How do I change the regular expression to add the + sign in the input?

Advertisement

Answer

Use this regex to allow +:

^[a-z0-9:_/+-]+$

The main point is that the unescaped hyphen must be at the end of the character class.

Here is a demo.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement