Asp.net Regular Expression Problem RRS feed

  • Question

  • User972064672 posted

    I have a regular expression  like below what my goal when <g class="gr_ gr_44 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="44" data-gr-id="44">user</g> changed <g class="gr_ gr_45 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="45" data-gr-id="45">dropdown</g> country in that  <g class="gr_ gr_42 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="42" data-gr-id="42">ddl</g> country selected index depending on the country <g class="gr_ gr_47 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="47" data-gr-id="47">i</g> have setted

    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 %>">

    But my problem is when there is no VatRegularExpression value. for example when <g class="gr_ gr_172 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="172" data-gr-id="172">i</g> select country <g class="gr_ gr_125 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="125" data-gr-id="125">germany</g> 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<g class="gr_ gr_438 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" id="438" data-gr-id="438">.Can</g> you help me out <g class="gr_ gr_443 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="443" data-gr-id="443">please</g>

    Sunday, November 18, 2018 12:34 AM


  • User-893317190 posted

    Hi Rakib Ahmed,

    You have written your answer in your code.

    You could use RegtxtVatCode's enabled property.

    Below is my test code.

      <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"   >
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox1" ValidationExpression=""  ></asp:RegularExpressionValidator>

    Code behind.

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim ex As String = ""
            If DropDownList1.SelectedItem.Text = "germany" Then
                ex = ""
                ex = "\d+"
            End If
            If String.IsNullOrEmpty(ex) Then
                RegularExpressionValidator1.Enabled = False
                RegularExpressionValidator1.ValidationExpression = ex
                RegularExpressionValidator1.Enabled = True
            End If
        End Sub

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 19, 2018 5:50 AM