Hi
I'm looking to ensure that my textbox only accepts numbers .. AND ... mathematical operators + - . / *. an dmaybe a blank space
I can ensure that only number are included by using:
[code=cpp]
private void txtSurname_KeyP ress(object sender, KeyPressEventAr gs e)
{
if (e.Handled = !(Char.IsDigit( e.KeyChar)))
{
e.Handled = true;
}
}[/code]
OR
[code=cpp]
private void txtTel_KeyPress (object sender, KeyPressEventAr gs e)
{
if (((e.KeyChar < '0') || (e.KeyChar > '9')) && (e.KeyChar != '\b'))
{
e.Handled = true;
}
}
[/code]
My Questions then:
1. Which one of the above is better to use to ensure that only numbers are
used?
2. How can I change the better option above to also allow me to input the
specified operators.
Thanks in advance,
Lóan
I'm looking to ensure that my textbox only accepts numbers .. AND ... mathematical operators + - . / *. an dmaybe a blank space
I can ensure that only number are included by using:
[code=cpp]
private void txtSurname_KeyP ress(object sender, KeyPressEventAr gs e)
{
if (e.Handled = !(Char.IsDigit( e.KeyChar)))
{
e.Handled = true;
}
}[/code]
OR
[code=cpp]
private void txtTel_KeyPress (object sender, KeyPressEventAr gs e)
{
if (((e.KeyChar < '0') || (e.KeyChar > '9')) && (e.KeyChar != '\b'))
{
e.Handled = true;
}
}
[/code]
My Questions then:
1. Which one of the above is better to use to ensure that only numbers are
used?
2. How can I change the better option above to also allow me to input the
specified operators.
Thanks in advance,
Lóan
Comment