验证文本框 - 仅允许编号和期间。 [英] Validate textbox- allow number and period only.

查看:71
本文介绍了验证文本框 - 仅允许编号和期间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的文本框仅接受数字,但是当用户输入12.50时它仍然可以接受该值。



所以我的问题是我该如何允许我的文本框只接受数字和句点?

I want my textbox to accept numbers only, however when a user inputs "12.50" It can still accept the value.

SO my question is how do I allow my textbox to accept number and period only?

推荐答案

使用 RegularExpressionValidator [ ^ ]



使用此正则表达式 [ ^ ]


谷歌是你的朋友: Google [ ^ ]

请注意,您不应该在C#中执行此操作 - JavaScript这里很好 - 因为它需要每个按键进行到服务器的往返,这会使用户输入减慢到愚蠢的水平。
google is your friend here: Google[^]
Note that you should not do this in C# - JavaScript is good here - as it would require each keypress taking a round trip to the server, and that would slow user input to silly levels.


只需使用ajaxcontroltoolkit你可以做一个FilterTextboxExtender选项它很容易使用下面的代码

Ajax代码

Just use ajaxcontroltoolkit there is a FilterTextboxExtender option you can do it easily using following code
Ajax code
<ajaxtoolkit:toolkitscriptmanager runat="server" xmlns:ajaxtoolkit="#unknown"></ajaxtoolkit:toolkitscriptmanager>
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
        <ajaxtoolkit:filteredtextboxextender id="fte" runat="server" targetcontrolid="TextBox1" xmlns:ajaxtoolkit="#unknown">
            FilterMode="ValidChars" FilterType="Custom" ValidChars="012345689."></ajaxtoolkit:filteredtextboxextender>


这篇关于验证文本框 - 仅允许编号和期间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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