允许仅数字字符进入文本框 [英] allow Only numeric Characters into Textbox

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

问题描述

在我的网页中,我有一个文本框字段,
我想只允许使用数字字符;我该如何在c#

In My webpage I hav A Textbox Field,
In which I want to allow Only numeric Charecters,;How can i do it in c#

推荐答案

中做到这一点,这是另一个与您相似的问题.

如何限制用户输入字母在文本框中没有Web应用程序中的验证器? [
Here''s another question similar to yours.

how to restrict the user to enter alphabets in textbox without validators in web application?[^]


请编写JavaScript以仅允许数字

please write javascript for allowing numeric only

<pre>function AllowNumber(evt)// These function is used for Inserting only number
         {
            var charCode;
            charCode = (evt.which) ? evt.which : event.keyCode;
            if(charCode >=48 && charCode<=57)
            {
            return true;
            }
            else
            {
                alert("Please Enter Number Only");
                return false;
            }
         }




然后像这样调用您的代码




and call to your code like that

<pre><asp:textbox id="txtAMCAmount" runat="server" cssclass="TextBoxStyle" width="185px" onkeypress="return AllowNumber(this)" xmlns:asp="#unknown"></asp:textbox>


使用此javascript

use this javascript

function onlyNumbers(evt)
{
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;

}


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

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