Another way to test would be to use a regular expression. In general,
try/catch blocks shouldn't be used for controlling program flow, but in
this case it probably isn't a big deal, especially if most of the time
the numbers entered will truly be integers. If they are not and the
exception must be caught, there is a lot of overhead associated with
this. However, if only for the sake of avoiding bad habits, I would use
a regex approach. The following (C#) method should work for you:
private bool IsInteger(string test)
{
Regex reg = new Regex(@"^[-+]?[1-9]\d*$");
Match mat = reg.Match(test);
return mat.Success;
}
*NOTE:
If you don't want to accept negative numbers, remove the [-+]?
If you want to accept numbers that end with a '.0' as an integer you
could use: ^[-+]?[1-9]\d*\.?[0]*$
Regular expression curtesy of Chuck Scholton
(
http://regexplib.com/REDetails.aspx?regexp_id=268)
Best,
Brett
"=?Utf-8?B?RmF0Ym95Q2FudGVlbg==?=" <an*******@discussions.microsoft.com>
wrote in news:D7**********************************@microsof t.com:
If I have a textbox, Let use to input a text..
I want to check the input text is integer type or not
I use isnum() to validate it, but double type also pass the
validation.. I don't want to use Field Validation (asp.net) to check
it.
Any Function can check the input type is integer or not?
Thank You X 100!!