<script language="JavaScript"><!--
alert(!isNaN("--000"));
alert(!isNaN("0.11.3"));
alert(!isNaN("11.3"));
//--></script>
alert(!isNaN("--000"));
alert(!isNaN("0.11.3"));
alert(!isNaN("11.3"));
//--></script>
计算一个参数,检查它是否为数值。
核心函数
实现版本 Navigator 2.0: 仅在 Unix上
Navigator 3.0, LiveWire 1.0: 所有平台
语法
isNaN(testValue)
参数
testValue 你想要测试的值。
描述
isNaN 是一个内建的 JavaScript 函数。它并不是与任何对象关联的方法,而仅仅是语言的一部分。
在支持 NaN 的平台上,parseFloat 和 parseInt 函数将在计算并不是数值的值时返回“NaN”。isNaN 在传递过来的参数是“NaN”时返回真,否则返回假。
示例
下面的例子计算 floatValue,确定它是否为数值,以便调用相应的过程:
floatValue=parseFloat(toFloat)
if (isNaN(floatValue)) {
notFloat()
} else {
isFloat()
}
说得都不对吧.
当toFloat="123abc",他会返回真,我想连小学生都知道"123abc"不是数字吧.
floatValue=parseFloat(toFloat)
if (isNaN(floatValue)) {
notFloat()
} else {
isFloat()
}
isNaN()是会返回true
你可以在比较一下他们的长度
return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
return typeof a == 'boolean';
}
function isEmpty(o) {
var i, v;
if (isObject(o)) {
for (i in o) {
v = o[i];
if (!!isUndefined(v) && !!isFunction(v)) {
return false;
}
}
}
return true;
}
function isFunction(a) {
return typeof a == 'function';
}
function isNull(a) {
return typeof a == 'object' && !a;
}
function isNumber(a) {
return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
return (typeof a == 'object' && !!a) || isFunction(a);
}
function isString(a) {
return typeof a == 'string';
}
function isUndefined(a) {
return typeof a == 'undefined';
}
String.method('entityify', function () {
return this.replace(/&/g, "&").replace(/</g,
"<").replace(/>/g, ">");
});
var number;
number = new Number(charpos);
if (isNaN(number)) {
return false;
}
else if (number>=0) {
return true;
}
else {
return false;
}
return true;
}
如果validateForm_Num(strTemp)==false 则不为数字否则为数字,但对负数无效
function checkInt(e){
var code = (document.all)?(e.keyCode):(e.which)
if (code==0 || code==8) return true;
var ch=String.fromCharCode(code)
var elm = (document.all)?(e.srcElement):(e.target)
return ("0123456789".indexOf(ch)>-1 || (ch=="-" && (elm.value==null || elm.value=='')))
}//浮点数
function checkFloat(e){
var code = (document.all)?(e.keyCode):(e.which)
if (code==0 || code==8) return true;
var ch=String.fromCharCode(code)
var elm = (document.all)?(e.srcElement):(e.target)
return ("0123456789".indexOf(ch)>-1 || (ch=="." && elm.value.indexOf(".")==-1) || (ch=="-" && (elm.value==null || elm.value=='')))
}//正整数
function checkPositiveInt(e){
var code = (document.all)?(e.keyCode):(e.which)
if (code==0 || code==8) return true;
var ch=String.fromCharCode(code)
return ("0123456789".indexOf(ch)>-1)
}//正浮点数
function checkPositiveFloat(e){
var code = (document.all)?(e.keyCode):(e.which)
if (code==0 || code==8) return true;
var ch=String.fromCharCode(code)
var elm = (document.all)?(e.srcElement):(e.target)
return ("0123456789".indexOf(ch)>-1 || (ch=="." && elm.value.indexOf(".")==-1))
}//百分比 80%显示为80
function checkPercent(e){
var code = (document.all)?(e.keyCode):(e.which)
if (code==0 || code==8) return true;
var ch=String.fromCharCode(code)
var elm = (document.all)?(e.srcElement):(e.target)
return (("0123456789".indexOf(ch)>-1 || (ch=="." && elm.value.indexOf(".")==-1) || (ch=="-" && (elm.value==null || elm.value==''))) && ((elm.value+ch)*1.0<=100 && (elm.value+ch)*1.0>=-100 ))
}//百分比 80%显示为0.80
function checkPercentDecimal(e){
var code = (document.all)?(e.keyCode):(e.which)
if (code==0 || code==8) return true;
var ch=String.fromCharCode(code)
var elm = (document.all)?(e.srcElement):(e.target)
return (("0123456789".indexOf(ch)>-1 || (ch=="." && elm.value.indexOf(".")==-1) || (ch=="-" && (elm.value==null || elm.value==''))) && ((elm.value+ch)*1.0<=1 && (elm.value+ch)*1.0>=-1))
}