写入期间的数字文本框 [英] numeric textbox during writing in it

查看:99
本文介绍了写入期间的数字文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个文本框,我只想接受数字,而另一个文本框只接受字母.
我已经搜索了很多并编写了代码,但是所有这些都在离开文本框之后.
我需要在文本框中书写时的解决方案.

有任何帮助,请

谢谢

hi all,
i have a text box which i want to accept numbers only and another one which accepts letters only.
i have searched a lot and writing code , but all of them after leaving text box.
i want a solution during writing in text box.

Any Help , please

Thanks

推荐答案

您好,请使用以下代码:


Hi, use below code:


<asp:textbox id="txtBox" runat="server" onkeypress="return isNumeric(event);" xmlns:asp="#unknown"></asp:textbox>





function isNumeric(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode < 48 || charCode > 57))
            return false;
 else if ((charCode == 8 || charCode == 46 || charCode == 0 ))
return true
else
        return true;
    }



它还将接受十进制值.

仅适用于字母:



It will accept decimal values also.

For only alphabets:

function isAlphabet(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode < 123 && charCode > 96))
{
            return true;
}
else if ((charCode < 91 && charCode > 64))
{
return true
}
else if(charCode == 0 || charCode == 8)
{
return true
}
else
{
        return false;
}
    }


尝试一下:

JavaScript代码:

Try This:

JavaScript Code:

function isNumberKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

        return true;
    }



设计代码:



Design Code:

<asp:textbox id="txtNoOfPer" runat="server" onkeypress="return isNumberKey(event);" xmlns:asp="#unknown"></asp:textbox>


使用此代码-------------
此代码仅允许用户使用数值....


use this code -------------
this code allowing to user only numeric values.......


<html>
   <head>
   <script language="Javascript">
     
      function isNumberKey(evt)
      {
        var charCode = (evt.which) ? evt.which :   event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      
   </script>
   </head>
   <body>
      <input id="txtChar"  önkeypress="return isNumberKey(event)" type="text" name="txtChar">
   </input></body>
</html>


这篇关于写入期间的数字文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆