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?

1

6 Answers 6

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"/>
Sign up to request clarification or add additional context in comments.

2 Comments

That expression will only allow one digit
@bdukes, whoops. Forgot the + sign. Thanks.
0

Take a look at this post

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

1 Comment

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.
0

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

Comments

0

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

Comments

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.