ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Set ASP.Net RegularExpression Validator Expression based on DropDownList using C# and VB.Net<p>Hey <a class="username" rel="rakibxl">rakibxl</a>,</p> <p>Please refer below smaple.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:DropDownList runat=&#34;server&#34; ID=&#34;ddlCountry&#34; OnSelectedIndexChanged=&#34;Select&#34;&gt; &lt;asp:ListItem Text=&#34;Select&#34; /&gt; &lt;asp:ListItem Text=&#34;India&#34; /&gt; &lt;asp:ListItem Text=&#34;USA&#34; /&gt; &lt;asp:ListItem Text=&#34;UK&#34; /&gt; &lt;asp:ListItem Text=&#34;australia&#34; /&gt; &lt;/asp:DropDownList&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtVatCode&#34; /&gt; &lt;asp:RegularExpressionValidator ID=&#34;RegtxtVatCode&#34; Enabled=&#34;false&#34; runat=&#34;server&#34; ControlToValidate=&#34;txtVatCode&#34; Display=&#34;Dynamic&#34; CssClass=&#34;help-block&#34; ErrorMessage=&#34;WrongVatCode&#34;&gt; &lt;/asp:RegularExpressionValidator&gt; &lt;asp:Button Text=&#34;Validate&#34; runat=&#34;server&#34; OnClick=&#34;Validate&#34; CausesValidation=&#34;false&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">string VatRegularExpression = &#34;&#34;; protected void Select(object sender, EventArgs e) { if (ddlCountry.SelectedIndex &gt; 2) { VatRegularExpression = &#34;^[I-T]&#34;; } } protected void Validate(object sender, EventArgs e) { if (!string.IsNullOrEmpty(VatRegularExpression)) { RegtxtVatCode.Enabled = true; RegtxtVatCode.ValidationExpression = VatRegularExpression; } else { RegtxtVatCode.Enabled = false; RegtxtVatCode.ValidationExpression = VatRegularExpression; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private VatRegularExpression As String = &#34;&#34; Protected Sub [Select](ByVal sender As Object, ByVal e As EventArgs) If ddlCountry.SelectedIndex &gt; 2 Then VatRegularExpression = &#34;^[I-T]&#34; End If End Sub Protected Sub Validate(ByVal sender As Object, ByVal e As EventArgs) If Not String.IsNullOrEmpty(VatRegularExpression) Then RegtxtVatCode.Enabled = True RegtxtVatCode.ValidationExpression = VatRegularExpression Else RegtxtVatCode.Enabled = False RegtxtVatCode.ValidationExpression = VatRegularExpression End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/jDzWrBD.gif" alt="" width="363" height="154" /></p>https://www.aspforums.net:443/Threads/193275/Set-ASPNet-RegularExpression-Validator-Expression-based-on-DropDownList-using-C-and-VBNet/https://www.aspforums.net:443/Threads/193275/Set-ASPNet-RegularExpression-Validator-Expression-based-on-DropDownList-using-C-and-VBNet/Mon, 19 Nov 2018 06:42:32 GMT