为什么我的普通防爆pression在ASP.NET无法正常工作 [英] Why is my Regular Expression not work in ASP.NET
本文介绍了为什么我的普通防爆pression在ASP.NET无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 RegularEx pressionValidator
本表YYYY-MM-DD(例如:2012年11月29日)的日期,这里是我的前presion公司:
I want use a RegularExpressionValidator
for a date in this form yyyy-mm-dd (example: 2012-11-29) and here is my expresion:
/ ^(19 [789] \\ D | 20 [0123] \\ D) - (0 \\ D | 1 [012] | \\ D) - (31 | 30 | [012] \\ D | \\ D)$ /
/^(19[789]\d|20[0123]\d)-(0\d|1[012]|\d)-(31|30|[012]\d|\d)$/
我测试它在 http://www.quanetic.com/Regex 和它的作品,但如果我这样做是在我的asp.net应用程序不工作
I test it on http://www.quanetic.com/Regex and it works but if I do this in my asp.net application it doesn't work
<tr>
<td>Gültig ab:</td>
<td><asp:TextBox ID="txtVon" runat="server" ></asp:TextBox></td>
<td><asp:ImageButton ID="imgVon" runat="server" ImageUrl="images/Calender.ico" Width="15" Height="15" />
<asp:CalendarExtender runat="server" ID="E_Von" TargetControlID="txtVon" Format="yyyy-MM-dd" PopupButtonID="imgVon"/></td>
<td>
<asp:RequiredFieldValidator ID="ValVon"
runat="server" ForeColor="red"
ErrorMessage="*" ControlToValidate="txtVon"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regVon"
runat="server" ControlToValidate="txtVon"
ErrorMessage="*Format" ForeColor="red"
ValidationExpression="/^(19[789]\d|20[0123]\d)\-(0\d|1[012]|\d)\-(31|30|[012]\d|\d)$/"></asp:RegularExpressionValidator>
</td>
</tr>
哪里错误?
推荐答案
只是删除字符在开始时并在与字符串/。
Just remove char "/" in the begining and in the and of the string.
,你将有
ValidationExpression="^(19[789]\d|20[0123]\d)-(0\d|1[012]|\d)-(31|30|[012]\d|\d)$"
这篇关于为什么我的普通防爆pression在ASP.NET无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文