IF statement and TextBox1

  • Thread starter Thread starter bebop
  • Start date Start date
B

bebop

Hi,

Is there a way to test if a user enters a number or
character text data in a TextBox using an IF statement?


If (TextBox1.Text == (number))
{

}


If (TextBox1.Text == (character text data))
{

}

bebop
 
bebop said:
Is there a way to test if a user enters a number or
character text data in a TextBox using an IF statement?

Hello bebop,

you can use the Parse-Method of Decimal, Int32, ... in a try/catch-clause.

You can also use the IsNumeric-Method of the
Microsoft.VisualBasic.dll-Assembly. This is a static method of the
Information-class.
But under the hood it will to the same like Parse.

Jürgen Beck
MCSD.NET, MCDBA, MCT
www.Juergen-Beck.de
 
On KeyDown, you can test that the event KeyChar isNumeric. If not, set
e.Handled to true
 
Thanks for the alternatives. I actually did find regular expressions to
be useful in determining whether a user entered a number or character
data in TextBox1.

bebop
 
Back
Top