0

My Question is how I'll be able to set a RegularExpressionValidator to numeric and special character like (),-.? Like (02)1234-123:

check my codes below.. its running properly.. only for numeric..

 &nbsp;<asp:TextBox ID="txtManual" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revNumericValidator" runat="server" 
ValidationExpression="^[0-9]*$" ControlToValidate="txtManual" ErrorMessage="Must be       Numeric" />
1
  • Without knowing what pattern you are trying to match, it is impossible to say what the regular expression needs to be. Are you specifically trying to match input of the form shown in your example? Commented May 2, 2011 at 5:01

1 Answer 1

1

Change your validation expression to:

"^\(\d+\)\d+-\d+$"

This will match strings like (02)1234-123, but it will also match strings like (1212)1-123456, because it will match any number of digits in each group.

To limit the number of digits in each group you can use {n} where n is the number if characters to match. For example:

"^\(\d{2}\)\d{4}-\d{3}$"

Here is a link to a "cheat sheet' for regular expressions.

http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

Sign up to request clarification or add additional context in comments.

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.