is there a simple way to suppress certain keystrokes within a textbox? for example if i only want to allow numbers.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There's nothing built-in, you will need to write some JavaScript to capture and ignore the keys you want to disallow.
Or you can use this FilteredTextBox control extender, from the ASP .NET AJAX Control Toolkit
回答2:
You could also use a <asp:CompareValidator>. E.g.
<asp:CompareValidator ID="valNumbersOnly" runat="server"
ControlToValidate="controlYouWantToValidate"
Operator="DataTypeCheck"
Type="Integer"
ErrorMessage="Please enter only numbers">*</asp:CompareValidator>
Or you could go even further and use a regular expression validator.
These solutions will work with and without javascript, so they will validate client side and server side. Not everyone has javascript turn on!
HTHs, Charles