Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate integer value

Status
Not open for further replies.

logi2000

Programmer
Jun 17, 2003
221
CR
is there any function in C# that validate if a data in a variable is an integer or not ?
 
Do you mean if a string is numeric?

Cause if you have an integer datatype, then it'll be an integer.
;)

You can use

Code:
IsNumeric(string)

and that will return a boolean value about whether its numeric or not.

hth

D



 
Is it a string you have the 'value' in? Do you want to check this value and see if it is valid int value too?

If this is the case why not use the convert method and catch the exception if you guess the wrong type.
If its a type of variable that your after, you can use the GetType() method.

Please give us some more info.
Klaz
 
IsNumeric is part of the Visual Basic compatability namespace (Microsoft.VisualBasic).

You can use the int.Parse() method with try..catch block, or the other method you found will work too (be sure to allow for -/+ symbols as well).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
C# doesn't have IsNumeric?

Yet another reason why developers should choose VB.NET
;)

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top