Test for a number

J

john sutor

When getting input from a user in a text box, how can you test to see that
they entered a numeric set of charactyers ( 0 to .....)
 
N

Nicholas Paldino [.NET/C# MVP]

John,

It depends on what kind of number you are testing for. If you want any
kind of number, then you can probably use the static TryParse method on the
double type to see if the string is a valid number. If you need integers,
then you will probably want to try the static Parse method on the Int32
(int) type, but you would have to wrap the call in a try/catch block to
catch the exception that is thrown if the number is not the correct format.

You can also call the static IsNumeric method on the Information class
in the Microsoft.VisualBasic namespace in Microsoft.VisualBasic.dll.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top