Allowing only Numbers and Backspace in a Text Box in Windows Application

Rajesh_Kumar
Posted by Rajesh_Kumar under C# category on | Points: 40 | Views : 2456
private void txt_policy_version_KeyPress(object sender, KeyPressEventArgs e)	
{
if((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar != '\b'))
{
MessageBox.Show("Only Numbers are Allowed");
e.Handled = true;
}
else
{
e.Handled = false;
}
}

Comments or Responses

Login to post response