Description
When using predefined validation rules like alpha
, decimal
, greater_than
and less_than
the field can't be optional, since these rules still kick in, even if the field is empty.
Expected behavior and Suggestion
Most of the predefined rules should pass trough if the field is NULL
. Then use required
to check for empty fields.
There might be issues with 0 numbers / decimals and required (required
does not only check NULL
- empty(trim($str))
) but we could prevent these in custom or more specific rules instead of defining thousands of new rules like decimal_optional
.
But we can't check if the Field is NULL
before applying rules, because we want to be able to validate against NULL
in some rules like required
or maybe custom rules. So we have to check for NULL
in every rule separately.
Steps to reproduce
Set alpha
as validation rule, let the field blank and try to validate. In my opinion the validation error should only occur when using alpha
and required
together.
Quickfix
As stated in the comments, use the permit_empty
rule.
CodeIgniter 4 version
Released 4.0.3
Affected module(s)
Validation\{FormatRules, FileRules}
(at least)
Activity