nagarajug
May 11th, 2005, 05:20 AM
Hi,
I am using c# with windows application. I want to validate a text box. The textbox should take 'numbers','. ', '%' . I wrote the following code in the key press event of the text box.
if(e.KeyChar!=8)
{
if(e.KeyChar=='.' && txtSLAFee.Text.IndexOf(".")>=0)
e.Handled = true;
if(e.KeyChar == '%' && txtSLAFee.Text.IndexOf("%")>=0)
e.Handled = true;
if(e.KeyChar!='%' && e.KeyChar!='.' && !char.IsDigit(Convert.ToString(e.KeyChar),0))
e.Handled = true;
if(txtSLAFee.Text.EndsWith(".") && (e.KeyChar == '%'))
e.Handled=true;
if(txtSLAFee.Text=="" && e.KeyChar=='%')
e.Handled = true;
if(txtSLAtax.Text.EndsWith("%") && (e.KeyChar=='.'))
e.Handled=true;
if(txtSLAFee.Text.EndsWith("%"))
e.Handled=true;
}
if i enter 200% in the text box. It is not allowing me to enter after % and before % symbol. I want to enter before % . How can i solve this problem. If any ideas plz let me know.
Regards,
Raju....
I am using c# with windows application. I want to validate a text box. The textbox should take 'numbers','. ', '%' . I wrote the following code in the key press event of the text box.
if(e.KeyChar!=8)
{
if(e.KeyChar=='.' && txtSLAFee.Text.IndexOf(".")>=0)
e.Handled = true;
if(e.KeyChar == '%' && txtSLAFee.Text.IndexOf("%")>=0)
e.Handled = true;
if(e.KeyChar!='%' && e.KeyChar!='.' && !char.IsDigit(Convert.ToString(e.KeyChar),0))
e.Handled = true;
if(txtSLAFee.Text.EndsWith(".") && (e.KeyChar == '%'))
e.Handled=true;
if(txtSLAFee.Text=="" && e.KeyChar=='%')
e.Handled = true;
if(txtSLAtax.Text.EndsWith("%") && (e.KeyChar=='.'))
e.Handled=true;
if(txtSLAFee.Text.EndsWith("%"))
e.Handled=true;
}
if i enter 200% in the text box. It is not allowing me to enter after % and before % symbol. I want to enter before % . How can i solve this problem. If any ideas plz let me know.
Regards,
Raju....