Skip to main content

Bug Tracker

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 rwaldron comment:1

component: unfiledcore
owner: → shiroiyamii@gmail.com
status: newpending

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.

Changed November 06, 2011 12:28AM UTC by shiroiyamii@gmail.com comment:2

status: pendingnew

The problem still exist in the jQuery Edge.

Here is a test case that shows only the date problem

http://jsfiddle.net/hdswj/1/

and here is a test case that is more detailed

http://jsfiddle.net/hdswj/2/

Changed November 06, 2011 03:36AM UTC by rwaldron comment:3

On the "more detailed" test, I'm getting all passing tests, is that correct?

Changed November 06, 2011 02:09PM UTC by dmethvin comment:4

milestone: None1.7.1
owner: shiroiyamii@gmail.comdmethvin
priority: undecidedblocker
status: newassigned

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.

http://jsfiddle.net/dmethvin/vAPaq/

Changed November 07, 2011 04:26PM UTC by Dave Methvin comment:5

resolution: → fixed
status: assignedclosed

Fix #10690. Make sure .isNumeric() can't get a Date.

Also add tests for custom objects with a .toString() method.

Changeset: 795583d2936a48c6f0048e28f74c5fc71e3a60b0