title: How to avoid taking special characters in textbox of a Windows application
body: <p>I am developing the Windows application. 
  I have a form and I am trying to validate the text box on that form.</p>
  
  <p>I want to put some validation on a text box like the text box should accept only Alphabates, Didgits and comma.(No other characters like special symbols.)
  As well, it should accept the Enter key when cursor is in that text box.</p>
  
  <p>I am trying to write the code but some how its not working.
  But its still taking special characters like &lt;>/;'
  What changes I have to made ? </p>
  
  <p>here is the code...</p>
  
  <blockquote>
    <p>Key Down Event</p>
  </blockquote>
  
  <pre><code> Private Sub txtOLDBuildingName_KeyDown(sender As Object, e As KeyEventArgs) Handles txtOLDBuildingName.KeyDown
  
          ' Initialize the flag to false.
          nonNumberEntered = False
  
          ' Determine whether the keystroke is a number from the top of the keyboard. 
          If (e.KeyCode &lt; Keys.D0 And e.KeyCode &gt; Keys.D9) And (e.KeyCode &gt; Keys.A And e.KeyCode &lt; Keys.Z) Then
              nonNumberEntered = True
          End If
          'If shift key was pressed, it's not a number. 
          If Control.ModifierKeys = Keys.Shift Then
              nonNumberEntered = True
          End If
  
  
      End Sub
  </code></pre>
  
  <blockquote>
    <p>Key Press Event</p>
  </blockquote>
  
  <pre><code>  Private Sub txtOLDBuildingName_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtOLDBuildingName.KeyPress
             If nonNumberEntered = True Then
                 e.Handled = True
          End If
  
     End Sub
  </code></pre>