Open ollipal opened 3 years ago
Would completely agree. Sadly NaN
is considered a number
in JavaScript
so that's why isNumber
, notNull
and the first check of minNumber
are not failing.
typeof NaN // 'number'
NaN
is also not considered bigger
, smaller
, or equal
to any other number hence also passing the second part of the minNumber
check.
NaN < 0 // false
NaN > 0 // false
NaN === 0 // false
Would totally agree that at least minNumber
should fail in case the provided value
is NaN
.
Furthermore an additional notNaN
check would be nice as well.
I'd want to check in one validation that
userInput
is number and larger or equal to zero. To enableminNumber
check, I need to convert the user input String to Number, with eitherparseInt()
/parseFloat()
(which returnNaN
for""
) orNumber()
(which returns0
for""
and hides the fact that the input was empty)Code:
Result
So with this setup I'm not able to catch the empty user input.
The workaround is to validate both parsed and unparsed userInput, but I feel like
notNull
,isNumber
orminNumber(0)
should have failed the validation forNaN
, or did I use validation somehow incorrectly? Or would it possible to have for examplenotNaN
check (which I would be happy to contribute, if wanted)I'm using version 0.15.0