odbhut.shei.chhele
odbhut.shei.chhele

Reputation: 6234

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?

Upvotes: 2

Views: 398

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626747

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.

Upvotes: 2

Related Questions