简体   繁体   中英

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:

    <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

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:

            <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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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