I’m having some issues with codeigniter’s validation filter when using checkboxes. I typically used the numeric filter for checkboxes, presuming it would filter for 0 or 1 but now I see there are several instances in which this fails.
Does anyone know a regex that I can put in the preg_match to validate a checkbox?
I would like this to allow for booleans and a few others 1, 0, null, true, false, empty etc…
A checkbox only returns one value. It’s value (as indicated in its
value=attribute) or ‘true’. If the checkbox is not selected, it is not passed in the POST request. Therefore, for validation, you only need to check for 2 things:So:
Should do the trick nicely. Unless I’ve misunderstood your question in which case please comment.