title: C# if statement to test if value is not a number
body: <p>I am trying to save the .text of a label to a database but sometimes that label is an infinity symbol. To catch for this I have created an if statement which checks if the label is a number or not and throws a message box up to tell the user. However more often than not the label will be a decimal number and the if statement throws up the message box. I was wondering if anyone could help me out please? </p>
  
  <pre><code>private void btnSaveResults_Click(object sender, EventArgs e)
  {
      btnClearData.Enabled = true;
  
  
      if (System.Text.RegularExpressions.Regex.IsMatch(lblAerobicCap.Text, "[^0-9]"))
      {
          MessageBox.Show("Im sorry, there seems to have been an error in the inputting of the readings, please restart the test");
  
      }
  
  
      else
      {
          AthletesDetailsNew users = new AthletesDetailsNew();
  
          DateTime dateTimeVariable = DateTime.Now;
  
          users.Date_Of_Test = dateTimeVariable;
          users.First_Name = comboBoxFirstName.Text;
          users.Surname = comboBoxNewSurname.Text;
          users.Age = int.Parse(comboBoxAge.Text);
          users.Account_Number = int.Parse(comboBoxAccountNumber.Text);
          users.Aerobic_Capacity = /*Math.Truncate*/(decimal.Parse(lblAerobicCap.Text));
  
  
          DataClassDataContext dbCtx = new DataClassDataContext();
  
          dbCtx.AthletesDetailsNews.InsertOnSubmit(users);
  
          try
          {
              dbCtx.SubmitChanges();
              MessageBox.Show("Data saved");
          }
  
          catch
          {
              MessageBox.Show("Data failed to save");
  
          }
      }
  }
  </code></pre>