当前位置:编程学习 > C#/ASP.NET >>

在js控制Textbox输入是一个大于0小于100的数怎么写(可以有小数点),怎么在Textbox调用这个

在js控制Textbox输入是一个大于0小于100的数怎么写(可以有小数点),怎么在Textbox调用这个 --------------------编程问答-------------------- 用正则:
^[[^0]|\d{1,2}|100]$ --------------------编程问答-------------------- 错了  --------------------编程问答-------------------- 是啊,错了 --------------------编程问答-------------------- 那到底要怎么写啊 --------------------编程问答--------------------     var num = document.getElementById("Text3").value;
    if(isNaN(num)){alert("false"); return;}
    if(parseFloat(num)>0&&parseFloat(num)<100)
    {
      alert(num);
      return;
    }
    else
    {alert("false");return;} --------------------编程问答-------------------- <input .... OnKeyDown="return checkValue(this.value)" />

function checkValue(objValue)
{
  if (objValue<0 || .....) return false; //return false就是取消刚才的按键输入

   return true; 如果全部校验通过,return true就能接受那个keydown的输入
} --------------------编程问答--------------------

function change()
{
    var form = document.form1;
    var str=form.txtname.value;
    var patt=/[^\d\_]+/g;
    if(!str.match(patt))
    {
        if (str>0 & str<100)
        {
    alert("ok");
}
        else
    alert("input");
    }
    else
alert("not OK");
}
...
<body >
<form name="form1">
<input type="text" name="txtname" id="txtname" value="" onchange="javascript:change();">
</form>
</body>

--------------------编程问答-------------------- ^\d{0,2}\.0*[1-9]+\d*$|^[1-9]\d{0,1}$
不好意,开会去了,这个测试过了的哈,可以输入.5的形式,
不让输入.5的话,\d{0,2}改为\d{1,2} --------------------编程问答-------------------- 这个在C#中怎么写?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,