How to find if argument is numeric or not, using Javascript
Use the code below:
// checks to see whether the input is a numeric string or not also includes "." and "-"
function IsNumeric(strString)
{
var strValidChars = "0123456789.-"; // valid characters for a numeric string
var strChar;
var result = true;
var i = 0
if (strString.length == 0) return false;
// check to see if strString consists of valid characters listed in strValidChars
while (i < strString.length && result == true)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1) return false;
i++;
}
return result;
}
Please feel free to use the comments form below if you have any questions or need more explanation on anything. Use the icons below to share this tutorial with your friends.
tags cloud
popular searches
free download for mysql database server 5.1.5, php, linux, mysql mysql, mysql, java, install mysql, gearman, ubuntu, tools, source code, bison, mysql initialization, install cairo, laptop
Similar Tutorials:
- Javascript: Encoding Values in XML Strings for AJAX / Web 2.0
- Trim whitespaces from both ends of a string, using Javascript
- Removing Ending Whitespaces from a String (Right Trim), using Javascript
- Sleep/Pause for specified number of seconds
- Removing Whitespaces from Beginning of a String (Left Trim), using Javascript
Tutorials in 'Web Development > Javascript' (more):
- Trim whitespaces from both ends of a string, using Javascript
- Sleep/Pause for specified number of seconds
- Javascript: Encoding Values in XML Strings for AJAX / Web 2.0
- Removing Whitespaces from Beginning of a String (Left Trim), using Javascript
- How to execute a function at regular intervals using Javascript


Comments (write a comment):
0 comments so far. Be the first one to leave a comment on this article.