1

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

How can I do that ?

Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174
  • If you have access to his keyboard remove the alphabetic keys. Not every solution needs to be software. – John K Jun 15 '10 at 18:07

5 Answers5

5

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
  • 54,410
  • 22
  • 144
  • 164
2

see this thread for a jquery solution How to allow only numeric (0-9) in HTML inputbox using jQuery?

Community
  • 1
  • 1
Donn Felker
  • 9,553
  • 7
  • 48
  • 66
1
<asp:TexBox runat="server" ID="TexBox1" />
<asp:RegularExpressionValidator runat="server" ValidationExpression="\d+" ControlToValidate="TexBox1" ErrorMessage="Error!" />
abatishchev
  • 98,240
  • 88
  • 296
  • 433
1
<input name="number" onkeyup="this.value=this.value.replace(/\D/g,'')">
Patrick Fisher
  • 7,926
  • 5
  • 35
  • 28
0

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
  • 1,536
  • 1
  • 16
  • 33