473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Integer Type (.net)

If I have a textbox, Let use to input a text.
I want to check the input text is integer type or no
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!!
Nov 18 '05 #1
4 1808
You can use Cint() for this. It will throw an OverflowException if the value
is out of range. For example, in this code try the value 2147483648 which is
one greater than the max for an integer:

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim intTest As Integer
Try
intTest = CInt(TextBox1.Text)
Label1.Text = intTest.ToString
Catch ex As OverflowException
Label1.Text = "That was not an integer"
End Try
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server">2147483648</asp:TextBox></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>

"FatboyCanteen" <an*******@discussions.microsoft.com> wrote in message
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!!


Nov 18 '05 #2
Could you not use a CompareValidator and set the type to Compare(or datatype
check, can't remember the specifics) and set the datatype to Integer? That
would prevent a postback, but requires additional space in the form
designer.

Morgan

"FatboyCanteen" <an*******@discussions.microsoft.com> wrote in message
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!!

Nov 18 '05 #3
Or, if you're using C#, you can use Convert.ToInt32(), which also works with
VB.Net.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:#H*************@TK2MSFTNGP11.phx.gbl...
You can use Cint() for this. It will throw an OverflowException if the value is out of range. For example, in this code try the value 2147483648 which is one greater than the max for an integer:

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim intTest As Integer
Try
intTest = CInt(TextBox1.Text)
Label1.Text = intTest.ToString
Catch ex As OverflowException
Label1.Text = "That was not an integer"
End Try
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server">2147483648</asp:TextBox></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P> <P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>

"FatboyCanteen" <an*******@discussions.microsoft.com> wrote in message
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!!

Nov 18 '05 #4
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!!


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon G Best | last post by:
Hello! The C++ standard library provides facilities for finding out the sizes (and other such stuff) of numeric types (::std::numeric_limits<>, for example). What I would like to do is to...
28
by: Timothy Madden | last post by:
Hello I've read here that only C language has a standard 64bit integer. Can you please tell me what are the reasons for this ? What is special about C language ? Can you please show me some...
11
by: Jason Heyes | last post by:
I would like to be able to extract an integer from a stream without having to write a test when I want the integer within some range. Unfortunately there is no range-checked integer type in the...
1
by: Joe | last post by:
Hi all, I have a linux c source code that stores a float value into a type int on many occasions. Is this possible in linux or does compiler round the float value into integral type? The strange...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
35
by: Frederick Gotham | last post by:
I'm writing a template, and I need to know the maximum value of a given integer type at compile time. something like: template<class NumType> class Arb { public: static NumType const max =...
3
by: veeman | last post by:
Can someone please write an example containing one element which value is integer type, and one attribute which value is also integer type: Is it something like this: <SomeAttribute...
11
by: zacariaz | last post by:
typedef char int(myint8); the above is realy what i wanna do, but ofcourse it cant be done this way. I have looked around for a 8 bit integer type, but no luck. the int8_t and simular still acts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.