Sometimes javascript can be really smart and sometimes it can be really dumb. For example there is no built in function for determining if a value is actually numeric. Happily though the internet provides. This handy code snippet comes courtesy of Kris Korsmo
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
For the fun of it lets break it down.
The parseFloat() function parses a string and returns a floating point number.
parseFloat(n)
Rules:
The isNaN() function determines whether a value is an illegal number (Not-a-Number), returning true if the value is NaN, and false if not.
The isFinite() function determines whether a number is a finite, legal number.
Tip: This function returns false if the value is +infinity, -infinity, or NaN.