Avi G wrote:
Hi,
what is the code to limit a textbox that will accept only text and not
number
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text = "numbers")
{
// do something
}
}
thanks
Hi Avi,
Try this:
///
private void button1_Click ( object s, EventArgs e )
{
bool isNumber = true;
foreach ( char c in textBox1.Text )
if ( ! char.IsDigit( c ) )
{
isNumber = false;
break;
}
if ( isNumber )
{
// Do something, if the textbox is a number.
}
else
{
// Do something, if the textbox isn't a number.
}
}
///
You could use 'TryParse' but if the number is too big to fit in the testing
data structure, then you're up the creek. This will ensure only numeric
digits appear in the textbox.
-- Tom Spink