I have a numeric validation rule for 0-50. This should only allow numbers greater than or equal to zero but less than or equal to 100.

But the validation allows -1 to be entered.

Comments

svendecabooter’s picture

Yes this is indeed a problem...
Actually the 0 symbol has been abused as a placeholder symbol in the current system.
Also the - symbol as a separator is in fact confusing, because it's used to split the range min & max, and could be a minus symbol as well.
This is bad design from my part...

There are 2 ways to fix this, but both will break current implementations that people might already have:
remove usage of 0 as placeholder and replace - as well:
The rules would then be as following:

  • empty: no value validation
  • "100": greater than or equal to 100
  • "|100": less than or equal to 100 (including negative numbers)
  • "0|100": greater than or equal to 0 & less than or equal to 100
  • "10|100": greater than or equal to 10 & less than or equal to 100
  • "-10|-5": greater than or equal to -10 & less than or equal to -5

This will however terribly break existing rules, so i'd need to write an upgrade script. People should also be made aware of this change when upgrading, so they can verify their validation rules are still working as expected.

Don't allow negative numbers:
When creating this validation rule I didn't account for negative numbers, so that's why the problems with them are present.
We could just not allow any negative numbers, but that might also break for people who got the rules working for allowing negative numbers (although at first sight that couldn't be the case...)

I'll have to think some more on how to solve this.

svendecabooter’s picture

By the way: if this is urgent, you could probably work around this by creating a regex validation rule instead. Shouldn't be to hard to find a regex for that case...

svendecabooter’s picture

Status: Active » Fixed

I chose to refactor the numeric range setting by chosing the first proposal (see above).
A migration script has been added (through update.php) to move the existing range syntax to the new syntax.

This will thus also allow negative values from now on.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.