views:

44

answers:

4

Hey,

I have a TextBox and I want that the user type just numbers, not other format.

How can I do that ?

+3  A: 

Use a regular expression validator:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Please Enter Only Numbers" Style="z-index: 101; left: 424px; position: absolute;
top: 285px" ValidationExpression="^\d+$" ValidationGroup="check"></asp:RegularExpressionValidator>
dcp
+1  A: 
<asp:TexBox runat="server" ID="TexBox1" />
<asp:RegularExpressionValidator runat="server" ValidationExpression="\d+" ControlToValidate="TexBox1" ErrorMessage="Error!" />
abatishchev
A: 

One way to do is by using the FilteredTextBox:

ilteredTextBox is an extender which prevents a user from entering invalid characters into a text box. Note that since this effect can be avoided by deactivating JavaScript, you should use this extender as a convenience for your users, but you must never expect that the data being sent to the server consists of "valid" chars only.

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/FilteredTextBox/FilteredTextBox.aspx

mga911