title: How to check the format of time input in a textbox
body: <p>I've a <code>textbox</code> called <code>HourTb</code>. I get the current time from <code>TimeSpan currentTime = DateTime.Now.TimeOfDay;</code> In order to make the time in 12-hour format, here's what I've done:</p>
  
  <pre><code>        if (currentTime &lt; TimeSpan.Parse("12:00")) //Morning
          {
              if (currentTime.Hours.ToString("00") == "00")
                  HourTb.Text = "12";
  
              else
                  HourTb.Text = currentTime.Hours.ToString("00");
  
              AmOrPmTb.Text = "AM";
          }
  
          else //Afternoon, night
          {
              HourTb.Text = (currentTime - TimeSpan.Parse("12:00")).Hours.ToString("00"); //12-hour format
              AmOrPmTb.Text = "PM";
          }
  </code></pre>
  
  <p>The problem that I'm facing now is how to check the value input to <code>HourTb</code> is a proper value in TextChangedEvent:</p>
  
  <ul>
  <li>If input > 12 or input = 00 or 0 only, <code>HourTb.Text = string.Empty;</code></li>
  <li>If input is single digit (e.g. 9), then <code>HourTb.Text = "09";</code></li>
  </ul>