1

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?

Nuke
  • 1,169
  • 5
  • 16
  • 33

2 Answers2

1

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.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
0

Add Display="None" So that the error message will not get displayed until you validate.

  <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>
Shreyas Achar
  • 1,407
  • 5
  • 36
  • 63