473,396 Members | 1,726 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.

IsNumeric

Tom
I need a way (Server Side) to check if a text box's value
is numeric or not.

Can anyone assist?

Thanks

Tom

Nov 15 '05 #1
7 5696
Tom,

If you want to use the IsNumeric function that comes with VB, then you
can set a reference to Microsoft.VisualBasic.dll in your project. IsNumeric
is defined as a static method on the Information class in the
Microsoft.VisualBasic namespace.

However, if you want a more ".NET" way (which isn't linked explicitly
for VB, some people have issue with this), you can use the static TryParse
method on the Double value type. This will attempt to parse a string, but
you will have to be a little more specific about what is acceptable and what
is not (through the use of number styles).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tom" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
I need a way (Server Side) to check if a text box's value
is numeric or not.

Can anyone assist?

Thanks

Tom

Nov 15 '05 #2
you could do int.parse(textBox.Text) and if no exception occures it is
definitely a number.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no fucking ads]
Nov 15 '05 #3
Tom, here are a couple of ways to do this:

1 Use the Parse method on any of the Int32, Int64, etc classes. If it
throws an exception it's not numeric.
2. Add a reference to the Microsoft.VisualBasic.dll assembly and then use
the IsNumeric function on the Microsoft.VisualBasic.Information class.
3. Write a regex statement that checks whether the string has anything but
numbers.

Hope that helps.

--
Greg Ewing [MVP]
http://www.citidc.com/

"Tom" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
I need a way (Server Side) to check if a text box's value
is numeric or not.

Can anyone assist?

Thanks

Tom

Nov 15 '05 #4
Hi Tom,

You could use a RegEx for this, here is one I'm using you may need to change
it to your needs

Regex r = new Regex(@"\d+|\d+\.\d+");
r.IsMatch( stringToTest );

basically it will test true for a construction like XXX.YYY with any number
of decimal places on each side of the "."

You could also try to use Convert.ToDouble|ToInt32 , etc and put it inside a
try/catch block

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Tom" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
I need a way (Server Side) to check if a text box's value
is numeric or not.

Can anyone assist?

Thanks

Tom

Nov 15 '05 #5
Tom
Ignacio Machin:

Thanks for your reply. Can you tell me where I can get
more information on regular expressions as your example is
not exactly what I am looking for but close.

I'm not familiar with Regex(@"\d+|\d+\.\d+") this.

Thanks
Tom
-----Original Message-----
Hi Tom,

You could use a RegEx for this, here is one I'm using you may need to changeit to your needs

Regex r = new Regex(@"\d+|\d+\.\d+");
r.IsMatch( stringToTest );

basically it will test true for a construction like XXX.YYY with any numberof decimal places on each side of the "."

You could also try to use Convert.ToDouble|ToInt32 , etc and put it inside atry/catch block

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Tom" <an*******@discussions.microsoft.com> wrote in messagenews:00****************************@phx.gbl...
I need a way (Server Side) to check if a text box's value is numeric or not.

Can anyone assist?

Thanks

Tom

.

Nov 15 '05 #6
Hi Tom,

You can get several books of regular expressions, in the MSDN you can also
find some doc related to .NET implementation of it, if you haven;t do
nothing with it I advise you to buy a book about them and read it first,
they can get very complex :)

Also take a look at this link, it's on JScript but the concepts are the same

http://msdn.microsoft.com/library/de...xpressions.asp

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tom" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
Ignacio Machin:

Thanks for your reply. Can you tell me where I can get
more information on regular expressions as your example is
not exactly what I am looking for but close.

I'm not familiar with Regex(@"\d+|\d+\.\d+") this.

Thanks
Tom
-----Original Message-----
Hi Tom,

You could use a RegEx for this, here is one I'm using you

may need to change
it to your needs

Regex r = new Regex(@"\d+|\d+\.\d+");
r.IsMatch( stringToTest );

basically it will test true for a construction like

XXX.YYY with any number
of decimal places on each side of the "."

You could also try to use Convert.ToDouble|ToInt32 , etc

and put it inside a
try/catch block

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Tom" <an*******@discussions.microsoft.com> wrote in

message
news:00****************************@phx.gbl...
I need a way (Server Side) to check if a text box's value is numeric or not.

Can anyone assist?

Thanks

Tom

.

Nov 15 '05 #7
Seeing as noone mentioned this, and even though I'm not sure how it would
perform ...

string numeric = "0123456789"
string num = textBox.Text;
for(int x = 0; x < num.Length; x++)
{
if( numeric.IndexOf(num[x]) == -1 )
{
// not a number, one of the characters was not 0 1 2 3 4 5 6 7 8 9
}
}

If you want a decimal point, add "." or "," to numeric.
Use a bool flag to make sure there is only one.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #8

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

Similar topics

8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
4
by: Eugene Anthony | last post by:
I have received the following feedback for the two functions bellow: "The ISNUMERIC test is WORTHLESS for checking for an INT value, because ISNUMERIC will happily accept DOUBLE values, such as...
14
by: Kenny | last post by:
Hello, I would like to know if the function IsNumeric requires a header like #include <iostream> to be functionnal thanks ken
8
by: John Bowman | last post by:
Hello, Does anyone have a good/reliable approach to implementing an IsNumeric() method that accepts a string that may represent a numerical value (eg. such as some text retrieved from an XML...
3
by: martin | last post by:
Hi, is there a dotnet function (other than the old isnumeric from VB) to check whether an object is numeric or not. also I notice that all the old vb functions such as split / isnumeric /...
7
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a...
8
by: moondaddy | last post by:
What's the .net framework equivalent of the vb function isnumeric? If there isn't one, how can I test a string variable to see if its a number or not? I don't want to use isnumeric if possible ...
12
by: sck10 | last post by:
Hello, I am trying to determine if a value is NOT numeric in C#. How do you test for "Not IsNumeric"? protected void fvFunding_ItemInserting_Validate(object sender, FormViewInsertEventArgs...
12
by: Paul | last post by:
Hi, I am trying to check a string to see if it's first 3 characters are numeric and if they are, to replace those 3 characters with something else. I've tried this but nothing happens... ...
17
by: MLH | last post by:
I have tested the following in immed window: ?isnumeric(1) True ?isnumeric(1.) True ?isnumeric(1.2) True ?isnumeric(1.2.2)
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.