How to check if a JavaScript number is a real, valid number?

后端 未结 6 1532
礼貌的吻别
礼貌的吻别 2020-12-16 15:30

MY code is:

function isNumber(n){
return typeof n == \'number\' && !isNaN(n);
}

window.onload=function(){
var a=0,b=1,c=2.2,d=-3,e=-4.4,f=10/3;
var          


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 16:01

    I use combination of parse and check for numbers.. as outlined below

    function isNumber(inputValue){ return ((parseFloat(inputValue) ==0 || parseFloat(inputValue)) && !isNaN(inputValue)); };

    hope this helps

提交回复
热议问题