Allowing only digits and alphabets in a textbox

Shreedar
Posted by Shreedar under C# category on | Points: 40 | Views : 430
Public enum
{
Digits,
Alphabets
}
Public Sample s;
Public Sample inputtype
{
set {s=value;}
get{return s;}
}
TextBox_Keypress event
{
if(s==Sample.Digits)
{
if(e.keychar>='0'&&e.keychar<='9')
e.Handled=false;
else
e.handled=true;
}
if(s==Sample.Alphabets)
{
if(e.keychar>='A'&&e.keychar<='Z'||e.keychar>='a'&&e.keychar<='z')
e.Handled=false;
else
e.Handled=true;
}

}

Comments or Responses

Login to post response