<asp:TextBox ID="txt_tmmaxset" runat="server" Width="176px" οnkeyup="javascript:checkkey('txt_tmmaxset')" Style="ime-mode: Disabled"></asp:TextBox>
function checkkey(kjmc)
{
//键盘按键值,47-60是大键盘数字键,190是大键盘小数点,95-106是小键盘数字键,110是小键盘小数点,46是Delete键,8是Backspace键
var key = event.keyCode;
var tmpstr=document.forms['form1'].elements[kjmc].value;
var tstr="";
//alert(key);
if( (key > 47 && key < 60) || (key == 190) || (key == 189) || (key == 109) || (key > 95 && key < 106)||
(key == 110) ||
(key == 46)||
(key == 8) ||
(key == 9) || //Tab
(key == 13)|| //Enter
(key == 37) || //上
(key == 38) || //左
(key == 39) || //右
(key == 40) ) //下
{
if(checkFormat(kjmc)==1||tmpstr=="")//检查格式通过
{
document.forms['form1'].elements['HB_check'].value=tmpstr;
}
else
{
document.forms['form1'].elements[kjmc].value=document.forms['form1'].elements['HB_check'].value;
}
}
else
{
document.forms['form1'].elements[kjmc].value=document.forms['form1'].elements['HB_check'].value;
}
}
//检查格式
function checkFormat(kjmc)
{
var retValue=0; //返回值
var DotCount=0; //小数点数量
var littleCount=2; //小数点后的位数(设置该值可限定可输入的小数点后的位数)
var j=0;
var tmpValue = document.forms['form1'].elements[kjmc].value;
for(i=0;i<tmpValue.length;i++)
{
if(tmpValue.charAt(i)=='.')
{
DotCount++;
j=i;
}
}
//判断小数点是否多于一个,判断小数点后的位数是否大于设定位数
if((DotCount>1) || ((j!=0) && (tmpValue.substring(j+1,tmpValue.length).length>=littleCount+1)) || tmpValue.substring(0,1)=='.')
{
var reg=/^[-+]?/d*$/;
if(reg.test(tmpValue)||tmpValue=='-')
{
retValue=1;
}
else
{
retValue=0;
}
}
else
{
var reg=/^[-/+]?/d+(/./d+)?$/;
if(reg.test(tmpValue)||tmpValue=='-')
{
retValue=1;
}
else
{
retValue=0;
}
}
return retValue;
}