在我的 ASP.NET Web 表单中,我有一个多行TextBox
,应该使用正则表达式验证器进行验证。文本框应该包含一个或多个字符串“a”(只是 'a' 字符,没有别的)。
到目前为止,我为我的RegularExpressionValidator
对象得到了这些正则表达式:
(?m:(^a$)+)
(?m:\A(^a$)+\Z)
(?m:^a$)
和其他一些。两者都不起作用。猜猜我还没有得到一些基本的东西。
你能告诉我我哪里错了吗?
这是涉及的代码。
一个按钮(仅用于回发):
<asp:Button ID="Button1" runat="server" Text="Button" />
文本框:
<asp:TextBox ID="TextBox1" runat="server" Rows="10" TextMode="MultiLine"></asp:TextBox>
和正则表达式验证器:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
ValidationExpression="(?m:(^a$)+)"></asp:RegularExpressionValidator>
该 Web 表单上没有其他内容。我只添加了这些控件并修改了属性。我什至使用 VS GUI 完成了所有这些工作。
使用 CustomValidator 并Regex.Match(TextBox1, @"(?m:(^a$)+)")
在其中进行操作就可以了。我猜 RegularExpressionValidator 出了点问题。