special chracters
i want text box accept numaric and this sign - nothing els
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Aug 20, 2013, 6:00 AM
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
const char hyphen = (char)0x2D;
const char delete = (char)0x08;
if (!char.IsNumber(e.KeyChar) && e.KeyChar != hyphen && e.KeyChar != delete)
e.Handled = true;
}
VulpesPosted Aug 20, 2013, 6:27 AM
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
const char hyphen = (char)0x2D;
const char delete = (char)0x08;
if (!char.IsNumber(e.KeyChar) && e.KeyChar != hyphen && e.KeyChar != delete)
e.Handled = true;
if (e.KeyChar == hyphen && textBox1.Text.Length > 0)
e.Handled = true;
}
Iftikar HussainPosted Aug 20, 2013, 6:02 AM
Are you looking for in ASP.NET or Windows Form?
Regards,
Iftikar