function chknum(NUM) { var i,j,strTemp; strTemp=".0123456789"; if ( NUM.length== 0) return 0 for (i=0;i<NUM.length;i++) { j=strTemp.indexOf(NUM.charAt(i)); if (j==-1) { return 0; } }
return 1; } 上面的是判断JS 下面是调用JS function check(){ var mostMoney=document.all("mostMoney").value; if(mostMoney!="" &&chknum(mostMoney)==0) { alert("不正确"); return; }
var size= document.getElementById("tb2").length;
if(size<0)
{
alert('长度大于0);
return flase;
}
else if(name.toString()=="NaN")
{
alert('请写入数字');
return
}
if(isNaN(document.getElementById("tb2").value))
alert('请写入数字');
function checkV(){
var r = /^\d+$/g;
if(! r.test(document.getElementById("txt1").value) )alert("false");
}
var theMask = "0123456789";
if (isEmpty(theNum)) return(false);
else if(theMask.indexOf(theNum) == -1) return(false);
return(true);
}
我项目就用这个。
{
var i,j,strTemp;
strTemp=".0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
return 0;
}
}
return 1;
}
上面的是判断JS
下面是调用JS
function check(){
var mostMoney=document.all("mostMoney").value;
if(mostMoney!="" &&chknum(mostMoney)==0)
{
alert("不正确");
return;
}
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function test()
{
var pattern = /^[1-9]\d*$/;
if (!pattern.test(document.forms[0].page.value))
{
alert("非正整数!");
return false;
}
}
</script>
</HEAD> <BODY>
<FORM METHOD=POST ACTION="">
<input name="page" type="text" size="14" maxlength="14">
<input type="button" onclick="return test();" value="button">
</FORM>
</BODY>
</HTML>