怎样用javascript限制文本框中不能输入数字,其它的都可以输入?

解决方案 »

  1.   

    2.只能输入数字的: 
    <input onkeyup='value=value.replace(/[\d]/g,'') ' onbeforepaste='clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))' ID='Text2' NAME='Text2'>
      

  2.   


    注释写的有问题..我已经做修改了..你试试就知道了..<input onkeyup='value=value.replace(/[\d]/g,'') ' onbeforepaste='clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))' ID='Text2' NAME='Text2'>
      

  3.   


    楼上的的这位大哥:我用的textbox.用你这种方法就有出错.还能有其它的办法吗?
      

  4.   


    在OnKeyUp调用此fun   输入的时候会自动清除非数字,和你的相反 要不你改一下
    function clearNoNum(obj)
    {
    obj.value = obj.value.replace(/[^\d.]/g,"");
    obj.value = obj.value.replace(/^\./g,"");
    obj.value = obj.value.replace(/\.{2,}/g,".");
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
    }
      

  5.   


    <asp:TextBox ID="txtSuggestion" runat="server" datatype="Require" msg="解决意见不能为空!" Width="440px"
                        onkeyup="value=value.replace(/[\d]/g,'') ' onbeforepaste='clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))"></asp:TextBox>
    我是这样写,但是还是能输入数字.
    不能限制.要限制不能输入数字的.
      

  6.   

    你的要求应该是输入的之中不包含0,1,....9的数值是吧
    正则的我不会写
    一般的话:
    string textValue=....;
    for(int i=0;i<=9;i++)
    {
       if(textValue.indexof(i)!=-1)
        {
           alert();
            return;
         }
    }基本意思是这样的,查找是否与1到9配的字符,又则提示,没有则通过
    代码可能有问题,你自己调试下