regular expression in asp.net
@"^[ 0-9+-\)\(]*$".
This is a r开发者_如何转开发egular expression on a textbox which i'm using to allow digits,space,+,=,()round brackets. but i'm not getting the desired result.
Your expression contains +- but your description says you want +=. It cant be that simple?
The usual way is to have code like the following in your aspx or ascx file:
<asp:TextBox ID="MyTextbox" runat="server"/>
<asp:RegularExpressionValidator ID="MyTextboxValidator" runat="server"
ControlToValidate="MyTextbox"
ValidationExpression="[ 0-9+\-\)\(]*]" ErrorMessage="Use digits and some others" />
When the user leaves the textbox and/or submits the form, the validator fires and blocks submission on error (displaying the message).
You could change the validation expression server-side:
MyTextboxValidator.ValidationExpression = "[ 0-9+\-\)\(]*]";
Notes:
- you don't need the ^ and $ to anchor this expression in this validator
- you need to escape the "-" else it will mean a range from "+" to ")"
精彩评论