title: Only allowing up to three digit numeric characters in a text box
body: <p>Is there a way to only allow a user to input a maximum number of characters into a text box? I want the user to input a mark/grade and only be able to input 0 - 100. Below I have code that monitors the keystroke and only allows for numbers to be input, but I want to find a way to only allow the user to input a number with a minimum value of 0 and a maximum of 100.  </p>
  
  <pre><code>private void TxtMark4_KeyPress(object sender, KeyPressEventArgs e)
  {
      if (e.KeyChar &lt; '0' || e.KeyChar &gt; '9' || e.KeyChar == ' ')
      {
          e.Handled = true;
      }
      else
      {
          e.Handled = false;
      }
  }
  </code></pre>
  
  <p>or I could use the following: </p>
  
  <pre><code>if (e.KeyChar &gt;= 48 &amp;&amp; e.KeyChar &lt;= 57 || e.KeyChar == ' ')
  {
      e.Handled = false;
  }
  else
  {
      MessageBox.Show("You Can Only Enter A Number!");
      e.Handled = true;
  }
  </code></pre>
  
  <p>But I would like to find a way to only allow three characters to be input maximum. </p>