JavaScript: Is string a number?
Question by Interest | 2012-07-02 at 21:55
I want to test using a JavaScript script, whether a given string is a number or not. Is there a good way to do it or do I have to check it with a regular expression?
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
JavaScript: Remove last character from string
Tip | 5 Comments
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
PHP: Get first Digit of Number or String
Tutorial | 0 Comments
jQuery: Scroll up and down with and without JavaScript
Tip | 0 Comments
JavaScript: Show and hide HTML area by clicking a link
Tutorial | 0 Comments
Android Programming: Receive Responce from HTTP POST Request
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Just use the function isNaN(), which is standing for "is Not a Number". The function accepts a string and returns true if the string is not a number and false if the string is a number.
Here is a small example:
"123" is a number, so "is Not a Number" is false. "abc" is not a number, therefore, the result is true.
With "1.0" and "1,0", you have to know, that in JavaScript, numbers are separated with a point instead of a comma. So, "1,0" is no number and in contrast, "1.0" is a number.
Last update on 2020-09-03 | Created on 2012-07-02