1

In my view page.I have a 10 textboxes for entering value, common name for all 10 fields that is 'value'. In my CodeIgniter validation that prevent only | character.

   for($i=1;$i<=10;$i++)
    {

            $value[$i]=$this->input->post('value'.$i);
           if ( !empty($value[$i]))
           {
           $this->form_validation->set_rules('value'.$i, 'Value', 'required|callback_Eventvalue['.$i.']');
           }
       }

And my call back function shown below

      public function Eventvalue($i) 
     {
       echo $i;
      if (  preg_match('|', $i));
      {
       $this->form_validation->set_message('Eventvalue', 'The %s field may not contain '|' character');
       }
     }

My for loop is working. I get each value inside the function. But the condition is not working.

halfer
  • 19,824
  • 17
  • 99
  • 186
roger nm
  • 277
  • 6
  • 19
  • Enable error_reporting. `|` is a meta character, and you have no regex delimiters. And if checking for a single character you don't need `preg_match` anyway. – mario Jul 04 '15 at 15:47
  • tri this.. if (strpos($i, '|') !== FALSE) { $this->form_validation->set_message('Eventvalue', 'The %s field may not contain '|' character'); } – robins Jul 04 '15 at 16:22

0 Answers0