title: How do I validate a TextBox with a RegularExpression based on a DropDownList Selection?
body: <p>I would like validate a Textbox based on a Dropdown List with regular expression. I would like to validate a credit card number based on the card type selected by the dropdown list.</p>
  
  <p>Here is a sample of my code:</p>
  
  <pre><code>&lt;table runat="server"&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;asp:Label ID="Label4" runat="server" Text="Credit Card Type"&gt;&lt;/asp:Label&gt;&lt;/td&gt;
      &lt;td&gt;&lt;asp:DropDownList ID="DropDownList1" runat="server"&gt;
              &lt;asp:ListItem Text="Visa" Value="Visa"&gt;&lt;/asp:ListItem&gt;
              &lt;asp:ListItem Text="MasterCard" Value="Mastercard"&gt;&lt;/asp:ListItem&gt;
          &lt;/asp:DropDownList&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;asp:Label ID="Label1" runat="server" Text="Card Number"&gt;&lt;/asp:Label&gt;&lt;/td&gt;
      &lt;td&gt;&lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; 
      &lt;td&gt;&lt;asp:CustomValidator ID=CustomValidator1 runat="server" ErrorMessage="Incorrect card, please re-renter!" ControlToValidate="TextBox1" Display="Dynamic" ForeColor="Red" OnServerValidate="CustomValidator1_ServerValidate"&gt;&lt;/asp:CustomValidator&gt;&lt;/td&gt;      
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;asp:Button ID="Button1" runat="server" Text="Submit" CommandName="Submit"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>And my other code:</p>
  
  <pre><code>protected void CustomValidation1_ServerValidate(object Source, ServerValidateEventArgs args)
  {
      string expression = "";
  
      switch (DropDownList.SelectedValue)
      {
          case "Visa":
          expression = "^(4)([0-9]{15})$";
          break;
          case "MasterCard":
          expression = "^(5[1-5])([0-9]{14})$";
          break;
      }
  }
  </code></pre>
  
  <p>So when I select on <code>MasterCard</code> on the Dropdown List and input numbers in the textbox. I would like to be validate with the regular expression <code>^(5[1-5])([0-9]{14})$</code>. And also when I select <code>Visa</code> on the Dropbox List and input numbers in the textbox, it will validate with the expression of <code>^(4)([0-9]{15})$</code>.</p>
  
  <p>Here it would be for MasterCard:</p>
  
  <p>Matches:
  <code>5212345678901234</code></p>
  
  <p>Does not Match:
  <code>1234567890123456</code></p>