title: ASP.net RegularExpressionValidator allows postback even if the input is not valid
body: <p>I'm trying to make a form for uploading images. I've placed a <code>RegularExpressionValidator</code> to check the extension of the selected file.
  Its <code>ValidationExpression</code> is : </p>
  
  <p><code>(?i:^.+(.jpg|.ttf|.png|.gif)$)</code></p>
  
  <p>But when i select an .exe file for example. The page does a postback and then shows me the error. And the .exe file is stored where it shouldn't.</p>
  
  <p>Here's my HTML code for the control:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/filippo_admin_page/admin_master.Master" AutoEventWireup="true" CodeBehind="a_gallery.aspx.cs" Inherits="photography.filippo_admin_page.a_gallery" %&gt;
      &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
          &lt;link rel="Stylesheet" type="text/css" href="css/a_gallery.css" /&gt;
      &lt;/asp:Content&gt;
      &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
          &lt;div id="whole_wrapper"&gt;
              &lt;fieldset&gt;
                  &lt;legend&gt;Insert new image:&lt;/legend&gt;
                  &lt;div id="controls_wrapper"&gt;        
                      &lt;ul&gt;
                          &lt;li&gt;
                              &lt;asp:Label AssociatedControlID="title_txt" runat="server" ID="title_lbl"&gt;Title:&lt;/asp:Label&gt;
                              &lt;asp:TextBox ID="title_txt" runat="server" placeholder="Image title"&gt;&lt;/asp:TextBox&gt;
                              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                  ControlToValidate="title_txt" ErrorMessage="RequiredFieldValidator" 
                                  ForeColor="Red" ValidationGroup="gallery_validation"&gt;Required!&lt;/asp:RequiredFieldValidator&gt;
                          &lt;/li&gt;
                          &lt;li&gt;
                              &lt;asp:Label AssociatedControlID="desc_txt" runat="server" ID="desc_lbl"&gt;Description:&lt;/asp:Label&gt;
                              &lt;asp:TextBox ID="desc_txt" runat="server" placeholder="Image description" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt;
                          &lt;/li&gt;
                          &lt;li&gt;
                              &lt;asp:Label AssociatedControlID="cat_txt" runat="server" ID="cat_lbl"&gt;Category:&lt;/asp:Label&gt;
                              &lt;asp:TextBox ID="cat_txt" runat="server" placeholder="Image category"&gt;&lt;/asp:TextBox&gt;
                              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                  ControlToValidate="cat_txt" ErrorMessage="RequiredFieldValidator" 
                                  ForeColor="Red" ValidationGroup="gallery_validation"&gt;Required!&lt;/asp:RequiredFieldValidator&gt;
                          &lt;/li&gt;
                          &lt;li&gt;
                              &lt;asp:Label ID="upload_lbl" runat="server"&gt;Select Image:&lt;/asp:Label&gt;
                              &lt;asp:FileUpload ID="upload_pnl" runat="server" /&gt;
                              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                  ControlToValidate="upload_pnl" ErrorMessage="RequiredFieldValidator" 
                                  ForeColor="Red" ValidationGroup="gallery_validation"&gt;Required!&lt;/asp:RequiredFieldValidator&gt;
                              &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                                  ControlToValidate="upload_pnl" ErrorMessage="RegularExpressionValidator" 
                                  ForeColor="Red" ValidationExpression="(?i:^.+(.jpg|.ttf|.png|.gif)$)" 
                                  ValidationGroup="gallery_validation"&gt;File must be an image.&lt;/asp:RegularExpressionValidator&gt;
                          &lt;/li&gt;
  
                          &lt;li&gt;
                              &lt;asp:Button ID="clear" runat="server" Text="Clear" UseSubmitBehavior="False" /&gt;
                              &lt;asp:Button ID="submit" runat="server" Text="Upload"  onclick="submit_Click" 
                                  ValidationGroup="gallery_validation"/&gt;                        
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
                  &lt;asp:Label ID="msg_lbl" Visible="false" runat="server"&gt;&lt;/asp:Label&gt;
              &lt;/fieldset&gt;
  
          &lt;/div&gt;    
      &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Here's the part of the validator:</p>
  
  <pre><code>&lt;li&gt;
      &lt;asp:Label ID="upload_lbl" runat="server"&gt;Select Image:&lt;/asp:Label&gt;
      &lt;asp:FileUpload ID="upload_pnl" runat="server" /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
          ControlToValidate="upload_pnl" ErrorMessage="RequiredFieldValidator" 
          ForeColor="Red" ValidationGroup="gallery_validation"&gt;Required!&lt;/asp:RequiredFieldValidator&gt;
      &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
          ControlToValidate="upload_pnl" ErrorMessage="RegularExpressionValidator" 
          ForeColor="Red" ValidationExpression="(?i:^.+(.jpg|.ttf|.png|.gif)$)" 
          ValidationGroup="gallery_validation"&gt;File must be an image.&lt;/asp:RegularExpressionValidator&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>I have <code>ValidationGroup</code> equals <code>gallery_validation</code> and is set on all controls that i want to validate, including the <code>submit</code> button it self.</p>
  
  <p>If you want the whole HTML code for the file just ask.</p>