Test for valid numbers
iangilman opened this issue ยท 10 comments
Unfortunately v8n().number().test(NaN)
returns true, which while technically correct according to JavaScript is usually not what you want.
A few options:
- Have
number
return false for NaN. - Have another
not.nan()
check. - Have a
finite()
check which returns false for NaN, Infinity, and -Infinity.
I think we should go with a rule finite
.
Do you want to make a PR @iangilman?
Iโm gonna say this should be 1.2.0 so 1.1.0 can finally go out.
It's already out man!
I definitely missed too much in two days :D
But you helped a lot though in this version. Thank you, man! ๐๐
To be honest number()
should really return false
for NaN
regardless of an additional rule. The same is true for Infinity
. These are odd quirks of JavaScript in my opinion. I would actually prefer to see something like a parameter for number()
where you can specify is these two should be included.
It seems to be a valid argument for number()
returning false instead of an additional rule.
Somebody working on this? I can take if a good first issue.
Great! Go ahead @jgpacheco.
Wow, things move fast around here! @imbrn Thank you for the invite; I was going to say I probably can't get to it right away, so I'm glad @jgpacheco has jumped in! :)