开发者

Problem in validation of numeric in textboxes asp.net

开发者 https://www.devze.com 2023-03-01 18:47 出处:网络
My Question is how I\'ll be able to set a RegularExpressionValidator to numeric and special character like (),-.? Like (02)1234-123:

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

 &nbsp;<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

0

精彩评论

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

关注公众号