Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jQuery.isNumeric consistent #2662

Closed
timmywil opened this issue Oct 18, 2015 · 3 comments
Closed

Make jQuery.isNumeric consistent #2662

timmywil opened this issue Oct 18, 2015 · 3 comments
Assignees
Milestone

Comments

@timmywil
Copy link
Member

Some people understand isNumeric as, "can I do math on this thing?" Others are asking, "Is this actually a number?" Now that we have no internal usage of jQuery.isNumeric, I think we can choose one or the other and update the documentation. Right now, it is inconsistent and a confusing confluence of the two.

@timmywil
Copy link
Member Author

@dmethvin, @gibson042 and I propose allowing all input and returning true for strings and numbers – whether primitive or object – that can be numeric.

@timmywil
Copy link
Member Author

jQuery.isNumeric = function( input ) {
  var type = jQuery.type( input );
  return ( type === "number" || type === "string" ) && ( input - parseFloat( input ) + 1 ) >= 0;
};

@dmethvin
Copy link
Member

I added the behavior change tag since there's that one strange case with a custom .toString() that we will no longer handle. It can just be mentioned in the release notes.

timmywil added a commit to timmywil/jquery that referenced this issue Oct 21, 2015
timmywil added a commit that referenced this issue Oct 25, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants