Welcome...



...All those moments will be lost in time, like tears in rain....

- soliloquy from Blade Runner


Bits and bytes do get lost, awash in the rain of data flow that is Internet. They slip away from us, never to found again... some of them will be captured here, many more will not... like tears in rain...



Friday, January 10, 2014

Javascript - Empty space in numeric field

 I run into the issue when isNaN was returning false for empty string.
 Turned out this is by design, because isNan is comparing coerced values - coercing empty string into 0, and of course, not having issue with 0 not being a number.
 To make sure that user has to enter 0, I added this to the check:

 isNan(parseInt(field))

Of course, this is not comprehensive solution, Douglas Crockford has more to say on this topic, especially on recognizing the numbers, but it worked for simple validation I was aiming for.

No comments:

Post a Comment