Set ASP.Net RegularExpression Validator Expression based on DropDownList using C# and VB.Net

Last Reply one year ago By pandeyism

Posted one year ago

I have a regular expression  like below what my goal when user changed dropdown country in that  ddl country selected index depending on the country i have set

But my problem is when there is no VatRegularExpression value. for example when i select country germany there is no regular expression for this country.then also still it is giving the error message but it should not give the error message.Can you help me out please

VatRegularExpression = sp.CountryVatRegularExpressionGet(ddlCountry.SelectedValue)  ---here i  am getting regular expression from database

If Not String.IsNullOrEmpty(VatRegularExpression) Then
    RegtxtVatCode.Enabled = True
    RegtxtVatCode.ValidationExpression = VatRegularExpression
End If

 

<asp:RegularExpressionValidator ID="RegtxtVatCode" Enabled="false"
    runat="server" ControlToValidate="txtVatCode" Display="Dynamic" CssClass="help-block"
    ErrorMessage="<%$ Resources: res, WrongVatCode %>">
</asp:RegularExpressionValidator>

 

This question does not have replies that have been liked.