Side navigation
#10690 closed bug (fixed)
Opened November 05, 2011 11:40PM UTC
Closed November 07, 2011 04:26PM UTC
Last modified March 08, 2012 08:16PM UTC
isNumeric
Reported by: | shiroiyamii@gmail.com | Owned by: | dmethvin |
---|---|---|---|
Priority: | blocker | Milestone: | 1.7.1 |
Component: | core | Version: | 1.7 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The isNumeric function use does not give the right result in every case. If the "number" is a date object it returns true, but a date is not a number.
the right functio should be
isNumeric: function( obj ) { return !isNaN(parseFloat(obj)) && isFinite(obj); }
Here's a site (not mine) that proves it:
http://dl.dropbox.com/u/35146/js/tests/isNumber.html
But 'cause it's not my site I copy pasted the site and add the jQuery function
Result:
http://img42.imageshack.us/content_round.php?page=done&l=img42/4489/20111106yami000.png
Attachments (0)
Change History (5)
Changed November 05, 2011 11:49PM UTC by comment:1
component: | unfiled → core |
---|---|
owner: | → shiroiyamii@gmail.com |
status: | new → pending |
Changed November 06, 2011 12:28AM UTC by comment:2
status: | pending → new |
---|
The problem still exist in the jQuery Edge.
Here is a test case that shows only the date problem
and here is a test case that is more detailed
Changed November 06, 2011 03:36AM UTC by comment:3
On the "more detailed" test, I'm getting all passing tests, is that correct?
Changed November 06, 2011 02:09PM UTC by comment:4
milestone: | None → 1.7.1 |
---|---|
owner: | shiroiyamii@gmail.com → dmethvin |
priority: | undecided → blocker |
status: | new → assigned |
I'd agree that a Date object isn't logically numeric, although +(new Date)
does yield a perfectly usable number and that is essentially what is being measured.
The general case where an object has a .toString()
still works for both approaches, and I think we *do* want that. As long as the proposed new code doesn't break that I'm okay with it.
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/
Open the link and click to "Fork" (in the top menu) to get started.