简体   繁体   English

正则表达式错误不显示

[英]RegEx Errors Not Displaying

I have several text boxes in a row on a table and I'm not able to see the error message due to this, at present only a star (*) is displaying which isn't helpful to the end user. 我在桌子上连续有几个文本框,由于这个原因,我看不到错误消息,目前仅显示一个星号(*),这对最终用户没有帮助。

Any ideas/solutions/fixes for this problem? 任何想法/解决方案/解决此问题的方法?

Below is my aspx code: 下面是我的aspx代码:

    <asp:TextBox ID="name" runat="server" Text='<%#bind("Name") %>'></asp:TextBox>

<asp:RequiredFieldValidator ID="FieldValidator" runat="server" 
ControlToValidate="name" ValidationGroup="vg" SetFocusOnError="True">*</asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegName" runat="server" ControlToValidate="name" 
ErrorMessage="* Required, no more than 20 characters allowed." ValidationGroup="vg" 
ValidationExpression="^[a-zA-Z''-'\s]{1,20}$">*</asp:RegularExpressionValidator>

Set a Validation Summary on the page and that will display the error message. 在页面上设置验证摘要,这将显示错误消息。 Don't put it between them instead of * as it'll set the boxes miles apart with blank space until the error is called. 不要将它们放在它们之间而不是*,因为它将使框与空格隔开一英里,直到调用错误为止。

Source: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.regularexpressionvalidator_properties(v=vs.110).aspx 来源: http : //msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.regularexpressionvalidator_properties(v=vs.110).aspx

Here's some code I just tested on Chrome put into an alert box so that the user can't miss it and you don't have to fiddle with whatever you're working on to accommodate for the summary: 这是我刚刚在Chrome上测试过的一些代码,放入了一个警告框,以使用户不会错过它,并且您不必费心处理正在进行的工作以适应摘要:

            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ErrorMessage="You may only enter a maxium of twenty characters."
            ControlToValidate="txtBx2"
            ValidationExpression="^[\s\S]{0,20}$" Display="None"/>

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM