Problem in validation of numeric in textboxes asp.net
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 f开发者_开发百科or numeric..
<asp:TextBox ID="txtManual" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revNumericValidator" runat="server"
ValidationExpression="^[0-9]*$" ControlToValidate="txtManual" ErrorMessage="Must be Numeric" />
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
精彩评论