I want to ensure that a certain text field does not contain a specific value. Is there any way for me to do this using CI's Form Validation class or do I have to write my own extension for it?
I would extend the form validation class: http://codeigniter.com/user_guide/general/creating_libraries.html
Something like
<?
class MY_Form_validation extends CI_Form_validation {
  function __constuct() {
    parent::__constuct();
  }
  function isnt($str,$field){
    $this->CI->form_validation->set_message('isnt', "%s contains an invalid response");
    return $str!==$field;
  }
}
?>
Your validation rule would be something like
trim|alpha_numeric|isnt[invalid value]
Or, you can create a callback function instead of extending the class. The form validation section of the CI user guide has a relevant example: http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks
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