I needed a validation rule that accepts only positive numbers. I saw that the library comes with a validationrule called "IsPositive", great!
Unfortunately when testing it it accepted the value 0, and when I checked the source it validates like: value >= 0.
The number 0 is neither negative or positive.
A rule accepting 0 and all positive numbers should be called isNonNegative, while isPositive should only accept values that are greater than 0.
Same goes for isNegative vs isNonPositive.
Changing this would obviously be a breaking change, however I believe this is very confusing and incorrect. Maybe some documentation should be created where this is mentioned, on top of an addition to the library with a rule isPositiveZeroExcluded or something.
Obviously it is easy to just create this as a custom rule
I needed a validation rule that accepts only positive numbers. I saw that the library comes with a validationrule called "IsPositive", great! Unfortunately when testing it it accepted the value 0, and when I checked the source it validates like:
value >= 0
. The number 0 is neither negative or positive. A rule accepting 0 and all positive numbers should be calledisNonNegative
, whileisPositive
should only accept values that are greater than 0. Same goes forisNegative
vsisNonPositive
.Changing this would obviously be a breaking change, however I believe this is very confusing and incorrect. Maybe some documentation should be created where this is mentioned, on top of an addition to the library with a rule
isPositiveZeroExcluded
or something.Obviously it is easy to just create this as a custom rule