UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

21 lines (20 loc) 840 B
function is_numeric(mixed_var) { // From: http://phpjs.org/functions // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: David // + improved by: taith // + bugfixed by: Tim de Koning // + bugfixed by: WebDevHobo (http://webdevhobo.blogspot.com/) // + bugfixed by: Brett Zamir (http://brett-zamir.me) // * example 1: is_numeric(186.31); // * returns 1: true // * example 2: is_numeric('Kevin van Zonneveld'); // * returns 2: false // * example 3: is_numeric('+186.31e2'); // * returns 3: true // * example 4: is_numeric(''); // * returns 4: false // * example 4: is_numeric([]); // * returns 4: false return (typeof mixed_var === 'number' || typeof mixed_var === 'string') && mixed_var !== '' && !isNaN(mixed_var); }