12 October, 2010

How to check for numeric value using Javascript

We can use some simple function to check numeric value using javascript. The following is code snippet that checks if a value is numeric or not, returns false if not numeric else returns true.
Hope this helps someone.

//following function is used to check for a numeric value
function is_numeric(numVal) {
return (typeof(numVal) === "number" || typeof(numVal) === "string") && numVal != "" && !isNaN(numVal);
var testThis = "123";

//check as follows
//returns true

No comments: