1

I am trying to add an exception to my RegularExpressionValidator

Basically I am populating a textbox with the text "Not supplied" if the user hasn't given us the information if they try and submit that field I have a RegularExpressionValidator which only allows 0-9 characters so it shows the error message.

Is there a way to add the exception "Not supplied" to my RegularExpressionValidator?

Here's the code for the RegularExpressionValidator

<asp:TextBox ID="tbEditFlightTime" CssClass="tbEditFlightTime" Visible="false" Width="100" runat="server"></asp:TextBox> 

<asp:RegularExpressionValidator ID="revFlightTime" runat="server" Display="Dynamic" ErrorMessage="<strong>Error</strong>" ControlToValidate="tbEditFlightTime" ValidationExpression="^[0-9]{4,4}$" SetFocusOnError="true" />

Thanks

captainsac
  • 2,484
  • 3
  • 27
  • 48
Jamie Taylor
  • 3,500
  • 21
  • 65
  • 99

1 Answers1

3

You can use an alternation:

<asp:RegularExpressionValidator ID="revFlightTime" runat="server"
    Display="Dynamic" ErrorMessage="<strong>Error</strong>"
    ControlToValidate="tbEditFlightTime"
    ValidationExpression="^(Not supplied|[0-9]{4,4})$"
    SetFocusOnError="true" />
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479