0

Update:

I can not use any plugin.

How do I enable only digits number to enter into the Textbox using asp.net using regexpression or jquery?

Terry
  • 981
  • 8
  • 27
Nick Kahn
  • 19,034
  • 87
  • 266
  • 401
  • http://stackoverflow.com/questions/995183/how-to-allow-only-numeric-0-9-in-html-inputbox-using-jquery/2403051#2403051 – Amr Elgarhy Mar 23 '11 at 16:05

6 Answers6

1

You can use a RegularExpressionValidator.

It won't actually stop the user from entering something other than numbers, but it will validate it for you on the client and server side.

<asp:RegularExpressionValidator id="RegularExpressionValidator1" 
                 ControlToValidate="MyTextBox"
                 ValidationExpression="\d+"
                 ErrorMessage="Please enter a number"
                 runat="server"/>
Brandon
  • 67,189
  • 30
  • 193
  • 221
0

Take a look at this post

Build one yourself http://snipt.net/GerryEng/jquery-making-textfield-only-accept-numeric-values

Community
  • 1
  • 1
Tim B James
  • 19,853
  • 4
  • 73
  • 99
  • why can you not use any plugin? If you read the post though there is a link to how you can build the code yourself. – Tim B James Mar 23 '11 at 16:05
0

Here is a full post about it: http://snipt.net/GerryEng/jquery-making-textfield-only-accept-numeric-values

Mohammed Swillam
  • 8,822
  • 3
  • 34
  • 45
0

Here's a post that already answers the question: jquery-numeric-input-mask using regex.

Community
  • 1
  • 1
firefox1986
  • 1,502
  • 9
  • 9
0

Regardless of your client-side behavior, you'll probably want a RegularExpressionValidator to verify the requirement on the server.

<asp:RegularExpressionValidator runat="server" 
                                ValidationExpression="\d+"                                    
                                ControlToValidate="NumberTextBox" 
                                ErrorMessage="Only numbers, please"
                                Text="*"
                                Display="Dynamic"
                                SetFocusOnError="true" />

If you have a jQuery plugin to more proactively restrict the input, you may also want to set EnableClientScript to false

bdukes
  • 144,904
  • 22
  • 145
  • 175
0

http://www.texotela.co.uk/code/jquery/numeric/ solved my problem perfectly.

jscs
  • 63,095
  • 13
  • 148
  • 192
Nick Kahn
  • 19,034
  • 87
  • 266
  • 401