Javascript - Check Numeric Variables

// Subtraction forces infinities to NaN // es6 const isNumeric = v => (typeof v === 'number' || typeof v === 'string') && !isNaN(v - parseFloat(v)); // es5 function isNumeric(value) { var type = typeof value; return (type === 'number' || type === 'string') && !isNaN(value - parseFloat(value)); }
Handy function to check if a variable is numeric.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.