开发者

enable only digits to enter into the Textbox using asp.net

开发者 https://www.devze.com 2023-02-19 11:20 出处:网络
Update: I can not use any plugin. How do I enable only digits number to enter into the Textbox us开发者_开发技巧ing asp.net using regexpression or jquery?You can use a RegularExpressionValidator.

Update:

I can not use any plugin.

How do I enable only digits number to enter into the Textbox us开发者_开发技巧ing asp.net using regexpression or jquery?


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"/>


Take a look at this post

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


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


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消