473,322 Members | 1,409 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,322 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 5694
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.