private void txtTest_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if((txtTest.Text.IndexOf("-")>-1 && e.KeyChar==(char)45))
{
e.Handled = true;
return;
}
if((txtTest.Text.IndexOf(".")>-1 && e.KeyChar==(char)46))
{
e.Handled = true;
return;
}
if(e.KeyChar == (char)Keys.Delete || e.KeyChar ==(char)Keys.Back)
{
return;
} if(!char.IsNumber(e.KeyChar)) e.Handled = true;
}
{
if((txtTest.Text.IndexOf("-")>-1 && e.KeyChar==(char)45))
{
e.Handled = true;
return;
}
if((txtTest.Text.IndexOf(".")>-1 && e.KeyChar==(char)46))
{
e.Handled = true;
return;
}
if(e.KeyChar == (char)Keys.Delete || e.KeyChar ==(char)Keys.Back)
{
return;
} if(!char.IsNumber(e.KeyChar)) e.Handled = true;
}
function fucCheckNUM(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)
{
//说明有字符不是数字
alert("你输入的不是数字"); return false;
}
}
</script>
<input type="text" name="HeTongZongE" size="28" onblur="return fucCheckNUM(document.myform.HeTongZongE.value)">
<script>
function isNumber(str)
{
var re=/^(-|\+)?\d+(\.\d+)?$/;
if(!re.test(str)){alert("不是数字")}
}
</script>
<input type=text onblur="isNumber(this.value)">
function checkInput(str)
{
if(str.indexOf("-") != -1)
{
if(/-\d+/.test(str))
alert("yes");
else
alert("no");
}
else
{
if(/\d*/.test(str))
alert("yes");
else
alert("no");
}
}
</SCRIPT>
<BODY>
<INPUT id="txt">
<INPUT type="button" value="check" onClick="checkInput(document.all.txt.value)">
</BODY>
var temnumber
</script>
正负数字<input name="Textbox_usefullifemonth" onfocus="javascript:temnumber=this.value" onkeyup="javascript:if (this.value >=0 || this.value <0 || this.value=='-'){temnumber=this.value;}else{this.value=temnumber}">
<br>
正数<input name="fff" onfocus="javascript:temnumber=this.value" onkeyup="javascript:if (this.value >=0){temnumber=this.value;}else{this.value=temnumber}">