The isNaN() function is used to check if the data contained in the Javascript variable is a number or not. The function returns true if the data is not a number and false if the data is a number.
This function is of great help while performing javascript validation to check if a user has entered only numeric values into the textboxes as specified by you.
Here is an example:
var a = “hi”;
var b = “123″;
if(isNaN(a))
{
alert(“Variable ‘a’ is not a number.”);
}
if(isNaN(b))
{
alert(“Variable ‘b’ is not a number.”);
}
The output will be “Variable ‘a’ is not a number.”
A note to remember: “isNaN() ” will return false for “1e1″ .
I mean, if you have numeric data with the letter ‘e’ in it, then the data is still considered to be numeric!
why is that?
Well, cause it treats the value to be exponential. So if you plan to validate for a numeric field and do not want to allow the letter ‘e’ then remember to validate it separately.
Well, as far as validating ‘e’ is considered… I wonder how you do that in Javascript!!
I mean we need to have a function which will tell us if a particular letter exists in a given data. Hmmmm… Donno if there exists a function like that in javascript. My next post will be on this