简体   繁体   中英

RegularExpressionValidator Error Message not visible

I have the following RegularExpressionValidator to allow only 4 digits number.

<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtPinCode" Display="Dynamic" ErrorMessage="Please make sure to select a PIN with four numeric digits" ValidationExpression="^\d{4,4}$" CssClass="caption">4 Digits Pincode</asp:RegularExpressionValidator>

It does Validate but doesn't show the error message:

Please make sure to select a PIN with four numeric digits

Instead Keeps showing the text 4 Digits Pincode . I want this text to get replaced by the Error message. Whats wrong?

添加Display="None" ,以便在您确认之前不会显示错误消息。

  <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtPinCode" Display="None" ErrorMessage="Please make sure to select a PIN with four numeric digits" ValidationExpression="^\d{4,4}$" CssClass="caption"></asp:RegularExpressionValidator>

Your "4 Digits Pincode" text goes into the Text property. This is defined as

the text displayed in the validation control when validation fails

The ErrorMessage property on the other hand is

the text for the error message displayed in a ValidationSummary control when validation fails

So they are both treated as error message, it's not "one or the other".

You maybe could use that "4 digit" text as placeholder on the input. Or just display it always, next to the validator.

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