javascript通用参数判断
//判断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));