Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with Billiam that you should extend the Form_validation class</p> <p>I find it is more likely that one would want to validate a white-list of possible string values rather than a black-list. For example, you know your 'shirt_size' field should only return the string values: 'xl','l','m','s'. My solution is to handle both cases.</p> <p>I use these methods in MY_From_validation:</p> <pre><code> /** * ENUM * The submitted string must match one of the values given * * usage: * enum[value_1, value_2, value_n] * * example (any value beside exactly 'ASC' or 'DESC' are invalid): * $rule['order_by'] = "required|enum[ASC,DESC]"; * * example of case-insenstive enum using strtolower as validation rule * $rule['favorite_corey'] = "required|strtolower|enum[feldman]"; * * @access public * @param string $str the input to validate * @param string $val a comma separated lists of values * @return bool */ function enum($str, $val='') { if (empty($val)) { return FALSE; } $arr = explode(',', $val); $array = array(); foreach($arr as $value) { $array[] = trim($value); } return (in_array(trim($str), $array)) ? TRUE : FALSE; } // -------------------------------------------------------------------- /** * NOT ENUM * The submitted string must NOT match one of the values given * * usage: * enum[value_1, value_2, value_n] * * example (any input beside exactly 'feldman' or 'haim' are valid): * $rule['favorite_corey'] = "required|not_enum['feldman','haim']"; * * @access public * @param string $str the input to validate * @param string $val a comma separated lists of values * @return bool */ function not_enum($str, $val='') { return ($this->enum($str,$val) === TRUE)? FALSE : TRUE; } </code></pre> <p>Using Billiam's example, the validation rule not allow string 'invalid value' would be something like:</p> <pre><code>trim|alpha_numeric|not_enum[invalid value] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload