473,785 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IsNumeric

Hello,

I am trying to determine if a value is NOT numeric in C#. How do you test
for "Not IsNumeric"?

protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsertE ventArgs e)

if (e.NewValues["Funding"] != "" && Not IsNumeric(e.New Values["Funding"]))
{
e.Cancel = true;
this.MessageTex t.Text += "Annual Rev: Numbers only.<br />";
}
}

I tried the following, but it seems awfully cluncky. Thanks, sck10
protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsertE ventArgs e)

// verify the textbox contains an integer
if (e.Values["Funding"].ToString() != "")
{
try {int i = Convert.ToInt32 (e.Values["Funding"].ToString(), 10);}
catch (FormatExceptio n i)
{
e.Cancel = true;
this.lblMessage Text.Text += "Annual Rev: Numbers only.<br />";
}
} // end if
}
Sep 2 '06 #1
12 3063
These might be interesting

http://www.hanselman.com/blog/Explor...mericForC.aspx
http://weblogs.asp.net/justin_rogers...29/100982.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"sck10" <sc***@online.n ospamwrote in message
news:eh******** ******@TK2MSFTN GP02.phx.gbl...
Hello,

I am trying to determine if a value is NOT numeric in C#. How do you test
for "Not IsNumeric"?

protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsertE ventArgs e)

if (e.NewValues["Funding"] != "" && Not
IsNumeric(e.New Values["Funding"]))
{
e.Cancel = true;
this.MessageTex t.Text += "Annual Rev: Numbers only.<br />";
}
}

I tried the following, but it seems awfully cluncky. Thanks, sck10
protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsertE ventArgs e)

// verify the textbox contains an integer
if (e.Values["Funding"].ToString() != "")
{
try {int i = Convert.ToInt32 (e.Values["Funding"].ToString(), 10);}
catch (FormatExceptio n i)
{
e.Cancel = true;
this.lblMessage Text.Text += "Annual Rev: Numbers only.<br />";
}
} // end if
}


Sep 2 '06 #2
Double.TryParse is a clean way to go. Here's an example where I've wrapped
it in a C# method:
http://www.tangiblesoftwaresolutions...0IsNumeric.htm
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"sck10" wrote:
Hello,

I am trying to determine if a value is NOT numeric in C#. How do you test
for "Not IsNumeric"?

protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsertE ventArgs e)

if (e.NewValues["Funding"] != "" && Not IsNumeric(e.New Values["Funding"]))
{
e.Cancel = true;
this.MessageTex t.Text += "Annual Rev: Numbers only.<br />";
}
}

I tried the following, but it seems awfully cluncky. Thanks, sck10
protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsertE ventArgs e)

// verify the textbox contains an integer
if (e.Values["Funding"].ToString() != "")
{
try {int i = Convert.ToInt32 (e.Values["Funding"].ToString(), 10);}
catch (FormatExceptio n i)
{
e.Cancel = true;
this.lblMessage Text.Text += "Annual Rev: Numbers only.<br />";
}
} // end if
}
Sep 2 '06 #3
Thanks Teemu...
"Teemu Keiski" <jo****@aspalli ance.comwrote in message
news:eQ******** ******@TK2MSFTN GP06.phx.gbl...
These might be interesting

http://www.hanselman.com/blog/Explor...mericForC.aspx
http://weblogs.asp.net/justin_rogers...29/100982.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"sck10" <sc***@online.n ospamwrote in message
news:eh******** ******@TK2MSFTN GP02.phx.gbl...
>Hello,

I am trying to determine if a value is NOT numeric in C#. How do you
test for "Not IsNumeric"?

protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsert EventArgs e)

if (e.NewValues["Funding"] != "" && Not
IsNumeric(e.Ne wValues["Funding"]))
{
e.Cancel = true;
this.MessageTex t.Text += "Annual Rev: Numbers only.<br />";
}
}

I tried the following, but it seems awfully cluncky. Thanks, sck10
protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsert EventArgs e)

// verify the textbox contains an integer
if (e.Values["Funding"].ToString() != "")
{
try {int i = Convert.ToInt32 (e.Values["Funding"].ToString(), 10);}
catch (FormatExceptio n i)
{
e.Cancel = true;
this.lblMessage Text.Text += "Annual Rev: Numbers only.<br />";
}
} // end if
}



Sep 2 '06 #4
Thanks David, I'll give it a shot...
"David Anton" <Da********@dis cussions.micros oft.comwrote in message
news:E0******** *************** ***********@mic rosoft.com...
Double.TryParse is a clean way to go. Here's an example where I've
wrapped
it in a C# method:
http://www.tangiblesoftwaresolutions...0IsNumeric.htm
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"sck10" wrote:
>Hello,

I am trying to determine if a value is NOT numeric in C#. How do you
test
for "Not IsNumeric"?

protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsert EventArgs e)

if (e.NewValues["Funding"] != "" && Not
IsNumeric(e.Ne wValues["Funding"]))
{
e.Cancel = true;
this.MessageTex t.Text += "Annual Rev: Numbers only.<br />";
}
}

I tried the following, but it seems awfully cluncky. Thanks, sck10
protected void fvFunding_ItemI nserting_Valida te(object sender,
FormViewInsert EventArgs e)

// verify the textbox contains an integer
if (e.Values["Funding"].ToString() != "")
{
try {int i = Convert.ToInt32 (e.Values["Funding"].ToString(), 10);}
catch (FormatExceptio n i)
{
e.Cancel = true;
this.lblMessage Text.Text += "Annual Rev: Numbers only.<br />";
}
} // end if
}

Sep 2 '06 #5
Hi sck10,

It seems you're converting lots of VB.NET code to C# recently, right? I
recommend you first write the code in VB.NET, and then use Reflector to
view its disassembled code in C#. Sometimes, VB.NET is using functions from
Microsoft.Visua lBasic.dll, if you do not want to reference this assembly,
you can also check its disassembled code in C# and try to incorporate it
into your code.

Regarding this question, please feel free to post here if you need anything
else.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 4 '06 #6
Yes, Walter, you are right about the conversion. I am trying to learn c#
and the best way for me is by converting my vb.net applications to c#.

Anyway, thanks again...
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:vZ******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi sck10,

It seems you're converting lots of VB.NET code to C# recently, right? I
recommend you first write the code in VB.NET, and then use Reflector to
view its disassembled code in C#. Sometimes, VB.NET is using functions
from
Microsoft.Visua lBasic.dll, if you do not want to reference this assembly,
you can also check its disassembled code in C# and try to incorporate it
into your code.

Regarding this question, please feel free to post here if you need
anything
else.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 4 '06 #7
Hi Walter,

I just downloaded the Reflector tool. Can you point me to where I would
find IsNumeric or IsDate so I could see how it converts to c#?

Thanks again, sck10

"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:vZ******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi sck10,

It seems you're converting lots of VB.NET code to C# recently, right? I
recommend you first write the code in VB.NET, and then use Reflector to
view its disassembled code in C#. Sometimes, VB.NET is using functions
from
Microsoft.Visua lBasic.dll, if you do not want to reference this assembly,
you can also check its disassembled code in C# and try to incorporate it
into your code.

Regarding this question, please feel free to post here if you need
anything
else.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 4 '06 #8
Hi sck10,

Thank you for your quick reply.

Here's the steps to get the source code of IsNumeric:

1) Create a simple VB.NET console application, type in following code:

Sub Main()
Dim s As String = "1.234"
If IsNumeric(s) Then
Console.WriteLi ne("s is numeric")
End If
s = "2006/9/1"
If IsDate(s) Then
Console.WriteLi ne("s is date")
End If
End Sub

2) Build it; in Reflector, open the generated exe; find the Main function,
double click it to see its disassembled code (make sure you selected "C#"
in the toolbar combobox):

[STAThread]
public static void Main()
{
string text1 = "1.234";
if (Versioned.IsNu meric(text1))
{
Console.WriteLi ne("s is numeric");
}
text1 = "2006/9/1";
if (Information.Is Date(text1))
{
Console.WriteLi ne("s is date");
}
}

3) Click on the "IsNumeric" function to navigate to its source. You will
learn that it's located in Microsoft.Visua lBasic.Compiler Services.Versio ned
as a static method, so you can reference Microsoft.Visua lBasic.dll in your
C# project and use this method directly; or you can write your version of
IsNumeric use the disassembled code as reference.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 4 '06 #9
Hi sck10,

Another note, if you checked Reflector's "View/Options/Show PDB Symbols"
and you're disassembling an assembly with full .pdb file, you will see the
correct variable name:

[STAThread]
public static void Main()
{
string s = "1.234";
if (Versioned.IsNu meric(s))
{
Console.WriteLi ne("s is numeric");
}
s = "2006/9/1";
if (Information.Is Date(s))
{
Console.WriteLi ne("s is date");
}
}

Previously I'm not checking that option, so the variable "s" has a generic
name "text1".
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 4 '06 #10

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

Similar topics

8
2323
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 following function in a validating class to use when needed. (Value = H880118A gave the error (like other 'unconvertible' strings)) Public Function Numeric(ByVal value) As Boolean
4
13276
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 89.11998811777 and other values that are simply *NOT* INT values." <% function isZip(input)
14
40146
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
2613
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 file)? Thus if you pass it "1" or "5.12345" it returns true, but "1b3q" it returns false? I know VB has this sort of function, but was wondering how to implement something similar in C#. I suppose I could use the Convert methods and catch any...
3
1765
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 / ubound etc are still availible by default in any VB.net web application. is this because the vb library is being imported?? would it be best to totally remove this library (assuming that it is being imported - which I can't see in my references) so...
7
2385
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 section that lists the Times, Buildings and rooms for courses. In this section I have a function called PadCell that takes3 parameters, one the value, one a padd count and one a a boolean input called StripNumeric, that if true, checks if the value...
8
2590
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 -- moondaddy@noemail.noemail
12
1666
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... newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")
17
2299
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
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.