NewOldMax / react-form-validator-core

Core validator component for react forms
MIT License
94 stars 44 forks source link

IsPositive accepts 0 while 0 is not a positive number #85

Open erikskoon opened 3 years ago

erikskoon commented 3 years ago

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