Welcome Guest, Not a member yet? Register   Sign In
Validation rules are back to front
#1

Hi,
Sorry if this is the wrong place to post this, but in the excellent user guide for Ci4 (https://codeigniter4.github.io/userguide...ation.html) in the Validation section its lists the validation commands. The "Less Than" and "Less than or equal to" rules are actually back to front. So the "Less Than" command actually has the less than or equal to logic/test and the "less than or equal to" command has the less than logic/test.

I did a validation test on a POST value of 1. With the "less than[1]" rule in place, it fails validation. If I change the rule to "less than or equal to[1]" then it passes validation! The manual states that the rule fails when true.

The manual correctly identifies this, but I wonder if the logic should be the other way around?

All the best,
Reply
#2

1 is not 'less than 1' so I would expect a false return.
1 is 'less than or equal to 1' so I would expect a true return.
Reply
#3

From the docs:

less_than: Fails if field is greater than or equal to the parameter value or not numeric.
less_than_equal_to: Fails if field is greater than the parameter value or not numeric.

So, from your test, with a POST value of 1:
less_than[1]: This rule expects a value that is less than 1. The POST value IS NOT less than 1, so it will fail.
less_than_equal_to[1]: This rule expects a value less than OR equal to 1. The POST value IS EQUAL TO 1, so it will pass the validation.
Reply
#4

1 < 1 - its false, 1 <= 1 - true, all right
Reply
#5

PHP Comparison Operators
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB