Javascript is_numeric : Variable handling : PHP functions in JavaScript JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » PHP functions in JavaScript » Variable handling »

 

Javascript is_numeric


Returns true if value is a number or a numeric string
Example 1

Running
1.is_numeric(186.31);

Could return
1.true
Example 2

Running
1.is_numeric('Kevin van Zonneveld');

Could return
1.false
function is_numeric( mixed_var ) {
    // Returns true if value is a number or a numeric string  
    // 
    // version: 902.223
    // discuss at: http://phpjs.org/functions/is_numeric
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // +   improved by: taith
    // *     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
    return !isNaN(mixed_var * 1);
}


HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo PHP functions in JavaScript
» Variable handling