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
  • 989
  • 8
  • 29
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • 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
  • 68,708
  • 30
  • 194
  • 223
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
  • 20,084
  • 4
  • 73
  • 103
  • 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
  • 9,119
  • 4
  • 36
  • 47
0

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

Community
  • 1
  • 1
firefox1986
  • 1,602
  • 11
  • 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
  • 152,002
  • 23
  • 148
  • 175
0

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

jscs
  • 63,694
  • 13
  • 151
  • 195
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406