DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Only Allow Numbers In Textbox

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

 void textBox_KeyPress(object sender, KeyPressEventArgs e)
e.Handled = !(Char.IsDigit(e.KeyChar) || e.KeyChar == '\b');