"valid_date" validation does not prevent submission of spaces |
I am using the Validation library to check that a date is either empty or a valid date using the following rules:
PHP Code: $validation->setRules(array( However, when a user submits input that contain only spaces, it passes the validation. I know that I can trim the result and check if it is empty, but it seems like this should error out.
Because you set `permit_empty`.
(02-27-2022, 06:19 PM)kenjis Wrote: Because you set `permit_empty`. Personally, I don't think that should be expected behavior, even with `permit_empty` being set. The PHP function empty will return FALSE if a variable is passed in with just whitespace. For example PHP Code: $a = " "; That would print out "NOT EMPTY". Why would permit_empty be any different? Therefore, if `permit_empty|valid_date[m/d/Y]` is set for validatin, I would expect that only input submitted with a value of FALSE, NULL, "", or a properly formatted date would be accepted.
Hi! When using the `permit_empty` rule, CI4 checks if the value provided is either an array or a string. If an array, it checks whether it is an empty array. If a string or can be casted to string, it trims it first then check against an empty string.
https://github.com/codeigniter4/CodeIgni...n.php#L234 Since you said you're passing an encapsed whitespace, CI4 trims it first. Naturally, this will pass the permit_empty check. |
Welcome Guest, Not a member yet? Register Sign In |