How to enable a button if regex expression is valid












0















I have a page on which there are two textboxes that have a regular expression on them.



ASPX Code TextBox 1



<asp:TextBox ID="txtCasesInsert" runat="server" Width="50px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCases" ControlToValidate="txtCasesInsert" ValidationGroup="InsertRecord"
runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexCases" ControlToValidate="txtCasesInsert"
ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
runat="server" />


ASPX Code TextBox 2



<asp:TextBox ID="txtPremiumInsert" runat="server" Width="50px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPremium" ControlToValidate="txtPremiumInsert"
ValidationGroup="InsertRecord" runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexPremium" ControlToValidate="txtPremiumInsert"
ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
runat="server" />


The regular expression works as intended for both text boxes.



What I need now is to be able to check the text being inputted into those text boxes and if the regular expression is valid, then enable my Insert button, otherwise, keep the button disabled.



Insert Button



<asp:Button ID="btnInsertRecord" Width="100px" Height="25px" runat="server" Text="Add Record"
CssClass="buttonBlue" ValidationGroup="InsertRecord" />


The reason I want to do this, is because when the regex has an error, the page still allows the user to insert data so I thought of disabling the button if the regex isn't successfull to prevent this.



I tried this C# If regex doesn't match then do something and I've also read up on Microsofts Regex documentation to learn more about what I can do with Regex's but I haven't found any information related to what I need.



I also tried creating a function with a TextChanged method hooked onto the textboxes but it didn't work. No error messages, just the button wasn't disabling when I inputted a wrong string. That's the problem I'm also having now with my current code. It's like nothing is happening. I've hooked the debugger on the _premiumMatch.Success line but again, nothing is happening, it just lets me proceed. When I created the TextChanged method for my button, I also tried adding it into my Page Load method but that disabled the button straight away.



Current VB Code (Example with one of the text boxes)



Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
Dim _premiumMatch = _regex.Match(txtPremiumInsert.Text)

If _premiumMatch.Success Then

Try
Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
_premium,
_cases,
_ddlMonths,
_ddlYear)
Catch ex As Exception
InformationBox.ShowErrorMessage("Record not added. Please try again")
End Try
loadLimitInsurances()
InformationBox.ShowSuccessMessage("New Record Inserted")
txtBranchInsert.Text = ""
txtPremiumInsert.Text = ""
txtCasesInsert.Text = ""
End If


Not sure what I'm doing wrong. Any suggestions? The above VB code, for now is in my buttons click event but even with an invalid regex, when I click the insert is still performed.



First Edit
Just tried calling the below function in my page load but the button disables straight away and does not become enabled if I input a valid regex. Again, example is for one textbox.



Protected Friend Sub CheckPremium() Handles txtPremiumInsert.TextChanged

Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
Dim _match As Match = _regex.Match(txtPremiumInsert.Text)

If _match.Success Then
btnInsertRecord.Enabled = True
Else
btnInsertRecord.Enabled = False
End If

End Sub


Second Edit



I have tried the above code and I've activated AutoPostBack on the textbox and still when I type an invalid expression it postbacks and activates my button.










share|improve this question





























    0















    I have a page on which there are two textboxes that have a regular expression on them.



    ASPX Code TextBox 1



    <asp:TextBox ID="txtCasesInsert" runat="server" Width="50px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvCases" ControlToValidate="txtCasesInsert" ValidationGroup="InsertRecord"
    runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="regexCases" ControlToValidate="txtCasesInsert"
    ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
    runat="server" />


    ASPX Code TextBox 2



    <asp:TextBox ID="txtPremiumInsert" runat="server" Width="50px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvPremium" ControlToValidate="txtPremiumInsert"
    ValidationGroup="InsertRecord" runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="regexPremium" ControlToValidate="txtPremiumInsert"
    ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
    runat="server" />


    The regular expression works as intended for both text boxes.



    What I need now is to be able to check the text being inputted into those text boxes and if the regular expression is valid, then enable my Insert button, otherwise, keep the button disabled.



    Insert Button



    <asp:Button ID="btnInsertRecord" Width="100px" Height="25px" runat="server" Text="Add Record"
    CssClass="buttonBlue" ValidationGroup="InsertRecord" />


    The reason I want to do this, is because when the regex has an error, the page still allows the user to insert data so I thought of disabling the button if the regex isn't successfull to prevent this.



    I tried this C# If regex doesn't match then do something and I've also read up on Microsofts Regex documentation to learn more about what I can do with Regex's but I haven't found any information related to what I need.



    I also tried creating a function with a TextChanged method hooked onto the textboxes but it didn't work. No error messages, just the button wasn't disabling when I inputted a wrong string. That's the problem I'm also having now with my current code. It's like nothing is happening. I've hooked the debugger on the _premiumMatch.Success line but again, nothing is happening, it just lets me proceed. When I created the TextChanged method for my button, I also tried adding it into my Page Load method but that disabled the button straight away.



    Current VB Code (Example with one of the text boxes)



    Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
    Dim _premiumMatch = _regex.Match(txtPremiumInsert.Text)

    If _premiumMatch.Success Then

    Try
    Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
    _premium,
    _cases,
    _ddlMonths,
    _ddlYear)
    Catch ex As Exception
    InformationBox.ShowErrorMessage("Record not added. Please try again")
    End Try
    loadLimitInsurances()
    InformationBox.ShowSuccessMessage("New Record Inserted")
    txtBranchInsert.Text = ""
    txtPremiumInsert.Text = ""
    txtCasesInsert.Text = ""
    End If


    Not sure what I'm doing wrong. Any suggestions? The above VB code, for now is in my buttons click event but even with an invalid regex, when I click the insert is still performed.



    First Edit
    Just tried calling the below function in my page load but the button disables straight away and does not become enabled if I input a valid regex. Again, example is for one textbox.



    Protected Friend Sub CheckPremium() Handles txtPremiumInsert.TextChanged

    Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
    Dim _match As Match = _regex.Match(txtPremiumInsert.Text)

    If _match.Success Then
    btnInsertRecord.Enabled = True
    Else
    btnInsertRecord.Enabled = False
    End If

    End Sub


    Second Edit



    I have tried the above code and I've activated AutoPostBack on the textbox and still when I type an invalid expression it postbacks and activates my button.










    share|improve this question



























      0












      0








      0








      I have a page on which there are two textboxes that have a regular expression on them.



      ASPX Code TextBox 1



      <asp:TextBox ID="txtCasesInsert" runat="server" Width="50px"></asp:TextBox>
      <asp:RequiredFieldValidator ID="rfvCases" ControlToValidate="txtCasesInsert" ValidationGroup="InsertRecord"
      runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
      <asp:RegularExpressionValidator ID="regexCases" ControlToValidate="txtCasesInsert"
      ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
      runat="server" />


      ASPX Code TextBox 2



      <asp:TextBox ID="txtPremiumInsert" runat="server" Width="50px"></asp:TextBox>
      <asp:RequiredFieldValidator ID="rfvPremium" ControlToValidate="txtPremiumInsert"
      ValidationGroup="InsertRecord" runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
      <asp:RegularExpressionValidator ID="regexPremium" ControlToValidate="txtPremiumInsert"
      ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
      runat="server" />


      The regular expression works as intended for both text boxes.



      What I need now is to be able to check the text being inputted into those text boxes and if the regular expression is valid, then enable my Insert button, otherwise, keep the button disabled.



      Insert Button



      <asp:Button ID="btnInsertRecord" Width="100px" Height="25px" runat="server" Text="Add Record"
      CssClass="buttonBlue" ValidationGroup="InsertRecord" />


      The reason I want to do this, is because when the regex has an error, the page still allows the user to insert data so I thought of disabling the button if the regex isn't successfull to prevent this.



      I tried this C# If regex doesn't match then do something and I've also read up on Microsofts Regex documentation to learn more about what I can do with Regex's but I haven't found any information related to what I need.



      I also tried creating a function with a TextChanged method hooked onto the textboxes but it didn't work. No error messages, just the button wasn't disabling when I inputted a wrong string. That's the problem I'm also having now with my current code. It's like nothing is happening. I've hooked the debugger on the _premiumMatch.Success line but again, nothing is happening, it just lets me proceed. When I created the TextChanged method for my button, I also tried adding it into my Page Load method but that disabled the button straight away.



      Current VB Code (Example with one of the text boxes)



      Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
      Dim _premiumMatch = _regex.Match(txtPremiumInsert.Text)

      If _premiumMatch.Success Then

      Try
      Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
      _premium,
      _cases,
      _ddlMonths,
      _ddlYear)
      Catch ex As Exception
      InformationBox.ShowErrorMessage("Record not added. Please try again")
      End Try
      loadLimitInsurances()
      InformationBox.ShowSuccessMessage("New Record Inserted")
      txtBranchInsert.Text = ""
      txtPremiumInsert.Text = ""
      txtCasesInsert.Text = ""
      End If


      Not sure what I'm doing wrong. Any suggestions? The above VB code, for now is in my buttons click event but even with an invalid regex, when I click the insert is still performed.



      First Edit
      Just tried calling the below function in my page load but the button disables straight away and does not become enabled if I input a valid regex. Again, example is for one textbox.



      Protected Friend Sub CheckPremium() Handles txtPremiumInsert.TextChanged

      Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
      Dim _match As Match = _regex.Match(txtPremiumInsert.Text)

      If _match.Success Then
      btnInsertRecord.Enabled = True
      Else
      btnInsertRecord.Enabled = False
      End If

      End Sub


      Second Edit



      I have tried the above code and I've activated AutoPostBack on the textbox and still when I type an invalid expression it postbacks and activates my button.










      share|improve this question
















      I have a page on which there are two textboxes that have a regular expression on them.



      ASPX Code TextBox 1



      <asp:TextBox ID="txtCasesInsert" runat="server" Width="50px"></asp:TextBox>
      <asp:RequiredFieldValidator ID="rfvCases" ControlToValidate="txtCasesInsert" ValidationGroup="InsertRecord"
      runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
      <asp:RegularExpressionValidator ID="regexCases" ControlToValidate="txtCasesInsert"
      ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
      runat="server" />


      ASPX Code TextBox 2



      <asp:TextBox ID="txtPremiumInsert" runat="server" Width="50px"></asp:TextBox>
      <asp:RequiredFieldValidator ID="rfvPremium" ControlToValidate="txtPremiumInsert"
      ValidationGroup="InsertRecord" runat="server" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
      <asp:RegularExpressionValidator ID="regexPremium" ControlToValidate="txtPremiumInsert"
      ValidationExpression="[0-9]+(,[0-9]+)*" ForeColor="Red" ErrorMessage="Please seperate numbers with a comma"
      runat="server" />


      The regular expression works as intended for both text boxes.



      What I need now is to be able to check the text being inputted into those text boxes and if the regular expression is valid, then enable my Insert button, otherwise, keep the button disabled.



      Insert Button



      <asp:Button ID="btnInsertRecord" Width="100px" Height="25px" runat="server" Text="Add Record"
      CssClass="buttonBlue" ValidationGroup="InsertRecord" />


      The reason I want to do this, is because when the regex has an error, the page still allows the user to insert data so I thought of disabling the button if the regex isn't successfull to prevent this.



      I tried this C# If regex doesn't match then do something and I've also read up on Microsofts Regex documentation to learn more about what I can do with Regex's but I haven't found any information related to what I need.



      I also tried creating a function with a TextChanged method hooked onto the textboxes but it didn't work. No error messages, just the button wasn't disabling when I inputted a wrong string. That's the problem I'm also having now with my current code. It's like nothing is happening. I've hooked the debugger on the _premiumMatch.Success line but again, nothing is happening, it just lets me proceed. When I created the TextChanged method for my button, I also tried adding it into my Page Load method but that disabled the button straight away.



      Current VB Code (Example with one of the text boxes)



      Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
      Dim _premiumMatch = _regex.Match(txtPremiumInsert.Text)

      If _premiumMatch.Success Then

      Try
      Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
      _premium,
      _cases,
      _ddlMonths,
      _ddlYear)
      Catch ex As Exception
      InformationBox.ShowErrorMessage("Record not added. Please try again")
      End Try
      loadLimitInsurances()
      InformationBox.ShowSuccessMessage("New Record Inserted")
      txtBranchInsert.Text = ""
      txtPremiumInsert.Text = ""
      txtCasesInsert.Text = ""
      End If


      Not sure what I'm doing wrong. Any suggestions? The above VB code, for now is in my buttons click event but even with an invalid regex, when I click the insert is still performed.



      First Edit
      Just tried calling the below function in my page load but the button disables straight away and does not become enabled if I input a valid regex. Again, example is for one textbox.



      Protected Friend Sub CheckPremium() Handles txtPremiumInsert.TextChanged

      Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
      Dim _match As Match = _regex.Match(txtPremiumInsert.Text)

      If _match.Success Then
      btnInsertRecord.Enabled = True
      Else
      btnInsertRecord.Enabled = False
      End If

      End Sub


      Second Edit



      I have tried the above code and I've activated AutoPostBack on the textbox and still when I type an invalid expression it postbacks and activates my button.







      asp.net regex vb.net






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 7:50







      NikosV

















      asked Nov 28 '18 at 6:22









      NikosVNikosV

      10210




      10210
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Try this code:



          Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
          Dim FoundMatch As Boolean = _regex.IsMatch(textPremiumInsert.Text)

          If FoundMatch = True Then

          Try
          Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
          _premium,
          _cases,
          _ddlMonths,
          _ddlYear)
          Catch ex As Exception
          InformationBox.ShowErrorMessage("Record not added. Please try again")
          End Try
          loadLimitInsurances()
          InformationBox.ShowSuccessMessage("New Record Inserted")
          txtBranchInsert.Text = ""
          txtPremiumInsert.Text = ""
          txtCasesInsert.Text = ""
          End If


          The code above uses the Regex.IsMatch method to compare the string passed with the regex pattern. It returns true if the string matches the Regex pattern.






          share|improve this answer
























          • Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

            – NikosV
            Nov 28 '18 at 7:48











          • what is the value in the text box

            – preciousbetine
            Nov 28 '18 at 7:52











          • Please see second edit on updated post. The value can be any number with commas.

            – NikosV
            Nov 28 '18 at 7:54











          • use the Regex.IsMatch method in your second edit

            – preciousbetine
            Nov 28 '18 at 8:01











          • I'm not sure I understand.

            – NikosV
            Nov 28 '18 at 10:27











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53513311%2fhow-to-enable-a-button-if-regex-expression-is-valid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Try this code:



          Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
          Dim FoundMatch As Boolean = _regex.IsMatch(textPremiumInsert.Text)

          If FoundMatch = True Then

          Try
          Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
          _premium,
          _cases,
          _ddlMonths,
          _ddlYear)
          Catch ex As Exception
          InformationBox.ShowErrorMessage("Record not added. Please try again")
          End Try
          loadLimitInsurances()
          InformationBox.ShowSuccessMessage("New Record Inserted")
          txtBranchInsert.Text = ""
          txtPremiumInsert.Text = ""
          txtCasesInsert.Text = ""
          End If


          The code above uses the Regex.IsMatch method to compare the string passed with the regex pattern. It returns true if the string matches the Regex pattern.






          share|improve this answer
























          • Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

            – NikosV
            Nov 28 '18 at 7:48











          • what is the value in the text box

            – preciousbetine
            Nov 28 '18 at 7:52











          • Please see second edit on updated post. The value can be any number with commas.

            – NikosV
            Nov 28 '18 at 7:54











          • use the Regex.IsMatch method in your second edit

            – preciousbetine
            Nov 28 '18 at 8:01











          • I'm not sure I understand.

            – NikosV
            Nov 28 '18 at 10:27
















          1














          Try this code:



          Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
          Dim FoundMatch As Boolean = _regex.IsMatch(textPremiumInsert.Text)

          If FoundMatch = True Then

          Try
          Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
          _premium,
          _cases,
          _ddlMonths,
          _ddlYear)
          Catch ex As Exception
          InformationBox.ShowErrorMessage("Record not added. Please try again")
          End Try
          loadLimitInsurances()
          InformationBox.ShowSuccessMessage("New Record Inserted")
          txtBranchInsert.Text = ""
          txtPremiumInsert.Text = ""
          txtCasesInsert.Text = ""
          End If


          The code above uses the Regex.IsMatch method to compare the string passed with the regex pattern. It returns true if the string matches the Regex pattern.






          share|improve this answer
























          • Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

            – NikosV
            Nov 28 '18 at 7:48











          • what is the value in the text box

            – preciousbetine
            Nov 28 '18 at 7:52











          • Please see second edit on updated post. The value can be any number with commas.

            – NikosV
            Nov 28 '18 at 7:54











          • use the Regex.IsMatch method in your second edit

            – preciousbetine
            Nov 28 '18 at 8:01











          • I'm not sure I understand.

            – NikosV
            Nov 28 '18 at 10:27














          1












          1








          1







          Try this code:



          Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
          Dim FoundMatch As Boolean = _regex.IsMatch(textPremiumInsert.Text)

          If FoundMatch = True Then

          Try
          Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
          _premium,
          _cases,
          _ddlMonths,
          _ddlYear)
          Catch ex As Exception
          InformationBox.ShowErrorMessage("Record not added. Please try again")
          End Try
          loadLimitInsurances()
          InformationBox.ShowSuccessMessage("New Record Inserted")
          txtBranchInsert.Text = ""
          txtPremiumInsert.Text = ""
          txtCasesInsert.Text = ""
          End If


          The code above uses the Regex.IsMatch method to compare the string passed with the regex pattern. It returns true if the string matches the Regex pattern.






          share|improve this answer













          Try this code:



          Dim _regex As Regex = New Regex("[0-9]+(,[0-9]+)*")
          Dim FoundMatch As Boolean = _regex.IsMatch(textPremiumInsert.Text)

          If FoundMatch = True Then

          Try
          Company.Applications.ProductionEngine.BusinessAccess.ExcelFileContentUploadBusinessAccess.InsertLimitInsurance(_branch,
          _premium,
          _cases,
          _ddlMonths,
          _ddlYear)
          Catch ex As Exception
          InformationBox.ShowErrorMessage("Record not added. Please try again")
          End Try
          loadLimitInsurances()
          InformationBox.ShowSuccessMessage("New Record Inserted")
          txtBranchInsert.Text = ""
          txtPremiumInsert.Text = ""
          txtCasesInsert.Text = ""
          End If


          The code above uses the Regex.IsMatch method to compare the string passed with the regex pattern. It returns true if the string matches the Regex pattern.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 7:27









          preciousbetinepreciousbetine

          1,5771418




          1,5771418













          • Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

            – NikosV
            Nov 28 '18 at 7:48











          • what is the value in the text box

            – preciousbetine
            Nov 28 '18 at 7:52











          • Please see second edit on updated post. The value can be any number with commas.

            – NikosV
            Nov 28 '18 at 7:54











          • use the Regex.IsMatch method in your second edit

            – preciousbetine
            Nov 28 '18 at 8:01











          • I'm not sure I understand.

            – NikosV
            Nov 28 '18 at 10:27



















          • Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

            – NikosV
            Nov 28 '18 at 7:48











          • what is the value in the text box

            – preciousbetine
            Nov 28 '18 at 7:52











          • Please see second edit on updated post. The value can be any number with commas.

            – NikosV
            Nov 28 '18 at 7:54











          • use the Regex.IsMatch method in your second edit

            – preciousbetine
            Nov 28 '18 at 8:01











          • I'm not sure I understand.

            – NikosV
            Nov 28 '18 at 10:27

















          Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

          – NikosV
          Nov 28 '18 at 7:48





          Doesn't work I'm afraid. The problem is that the text box needs to post back to the server to validate. I've activated that on the updated code and it seems to work but I want to avoid a total page load.

          – NikosV
          Nov 28 '18 at 7:48













          what is the value in the text box

          – preciousbetine
          Nov 28 '18 at 7:52





          what is the value in the text box

          – preciousbetine
          Nov 28 '18 at 7:52













          Please see second edit on updated post. The value can be any number with commas.

          – NikosV
          Nov 28 '18 at 7:54





          Please see second edit on updated post. The value can be any number with commas.

          – NikosV
          Nov 28 '18 at 7:54













          use the Regex.IsMatch method in your second edit

          – preciousbetine
          Nov 28 '18 at 8:01





          use the Regex.IsMatch method in your second edit

          – preciousbetine
          Nov 28 '18 at 8:01













          I'm not sure I understand.

          – NikosV
          Nov 28 '18 at 10:27





          I'm not sure I understand.

          – NikosV
          Nov 28 '18 at 10:27




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53513311%2fhow-to-enable-a-button-if-regex-expression-is-valid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Futebolista

          Jornalista

          F# list compare