By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,939 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,939 IT Pros & Developers. It's quick & easy.

wanna check if string contains number (float or integer)

Mike Kypriotis
P: 37
in a forum found this
Expand|Select|Wrap|Line Numbers
  1. function isNumber(n) {
  2.   return !isNaN(parseFloat(n)) && isFinite(n);
  3. }
  4.  
as the best solution, is it? Plus why both !isNAN and isFinite() are used together, which weaknesses each other covers?
Dec 23 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
I donít know if it is the best solution, but it certainly is a good one.

see https://developer.mozilla.org/en/Jav..._Objects/isNaN why the use of isFinite is required.
Dec 23 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.