if (e.KeyChar >= 48 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; }