javascript通用参数判断

时间:2014-05-01 10:53:41   收藏:0   阅读:426

 

//判断value是小于等于max的数字
function isNumberMax(value, max){
    if(!isNumber(value) || !isNumber(max)){
        return false;
    }
    if(parseInt(value) <= max){
        return true;
    }
    return false;
}

 

//判断value是大于等于min的数字

function isNumberMin(value, min){
    if(!isNumber(value) || !isNumber(min)){
        return false;
    }
    if(parseInt(value) >= min){
        return true;
    }
    return false;
};

//判断value是否是数字

function isNumber(value) {
    if(value === "" || value === null)
        return false;
    if (typeof value === ‘number‘) {
        return true;
    };
    return !isNaN(value);
};

console.log(1,isNumber(111));

console.log(2,isNumber("111"));

console.log(3,isNumber(0));

console.log(4,isNumber("0"));

console.log(5,isNumber(null));

console.log(6,isNumber({}));

console.log(7,isNumber("ssdsd"));

console.log(8,isNumber(undefined));

console.log(9,isNumber());

console.log(10,isNumber(""));

console.log(11,isNumber("-1"));

console.log(12,isNumberMin(1,"-1"));

console.log(13,isNumberMax(1,9));

 

javascript通用参数判断,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!