Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Only allow numbers in textbox (See related posts)

// This can be expanded to limit the key pressed to whatever you want
//In this scenario it only allows digits

   1  
   2   void textBox_KeyPress(object sender, KeyPressEventArgs e)
   3  {
   4  e.Handled = !(Char.IsDigit(e.KeyChar) || e.KeyChar == '\b');
   5  }

You need to create an account or log in to post comments to this site.


Click here to browse all 5556 code snippets

Related Posts