Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > IsNumeric

Reply
Thread Tools

IsNumeric

 
 
sck10
Guest
Posts: n/a
 
      09-02-2006
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 e)

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

I tried the following, but it seems awfully cluncky. Thanks, sck10
protected void fvFunding_ItemInserting_Validate(object sender,
FormViewInsertEventArgs e)

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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      09-02-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 e)
>
> if (e.NewValues["Funding"] != "" && Not
> IsNumeric(e.NewValues["Funding"]))
> {
> e.Cancel = true;
> this.MessageText.Text += "Annual Rev: Numbers only.<br />";
> }
> }
>
> I tried the following, but it seems awfully cluncky. Thanks, sck10
> protected void fvFunding_ItemInserting_Validate(object sender,
> FormViewInsertEventArgs e)
>
> // verify the textbox contains an integer
> if (e.Values["Funding"].ToString() != "")
> {
> try {int i = Convert.ToInt32(e.Values["Funding"].ToString(), 10);}
> catch (FormatException i)
> {
> e.Cancel = true;
> this.lblMessageText.Text += "Annual Rev: Numbers only.<br />";
> }
> } // end if
> }
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      09-02-2006
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_ItemInserting_Validate(object sender,
> FormViewInsertEventArgs e)
>
> if (e.NewValues["Funding"] != "" && Not IsNumeric(e.NewValues["Funding"]))
> {
> e.Cancel = true;
> this.MessageText.Text += "Annual Rev: Numbers only.<br />";
> }
> }
>
> I tried the following, but it seems awfully cluncky. Thanks, sck10
> protected void fvFunding_ItemInserting_Validate(object sender,
> FormViewInsertEventArgs e)
>
> // verify the textbox contains an integer
> if (e.Values["Funding"].ToString() != "")
> {
> try {int i = Convert.ToInt32(e.Values["Funding"].ToString(), 10);}
> catch (FormatException i)
> {
> e.Cancel = true;
> this.lblMessageText.Text += "Annual Rev: Numbers only.<br />";
> }
> } // end if
> }
>
>
>

 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      09-02-2006
Thanks Teemu...


"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:eQUeD$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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 e)
>>
>> if (e.NewValues["Funding"] != "" && Not
>> IsNumeric(e.NewValues["Funding"]))
>> {
>> e.Cancel = true;
>> this.MessageText.Text += "Annual Rev: Numbers only.<br />";
>> }
>> }
>>
>> I tried the following, but it seems awfully cluncky. Thanks, sck10
>> protected void fvFunding_ItemInserting_Validate(object sender,
>> FormViewInsertEventArgs e)
>>
>> // verify the textbox contains an integer
>> if (e.Values["Funding"].ToString() != "")
>> {
>> try {int i = Convert.ToInt32(e.Values["Funding"].ToString(), 10);}
>> catch (FormatException i)
>> {
>> e.Cancel = true;
>> this.lblMessageText.Text += "Annual Rev: Numbers only.<br />";
>> }
>> } // end if
>> }
>>
>>

>
>



 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      09-02-2006
Thanks David, I'll give it a shot...


"David Anton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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_ItemInserting_Validate(object sender,
>> FormViewInsertEventArgs e)
>>
>> if (e.NewValues["Funding"] != "" && Not
>> IsNumeric(e.NewValues["Funding"]))
>> {
>> e.Cancel = true;
>> this.MessageText.Text += "Annual Rev: Numbers only.<br />";
>> }
>> }
>>
>> I tried the following, but it seems awfully cluncky. Thanks, sck10
>> protected void fvFunding_ItemInserting_Validate(object sender,
>> FormViewInsertEventArgs e)
>>
>> // verify the textbox contains an integer
>> if (e.Values["Funding"].ToString() != "")
>> {
>> try {int i = Convert.ToInt32(e.Values["Funding"].ToString(), 10);}
>> catch (FormatException i)
>> {
>> e.Cancel = true;
>> this.lblMessageText.Text += "Annual Rev: Numbers only.<br />";
>> }
>> } // end if
>> }
>>
>>
>>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-04-2006
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.VisualBasic.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 ((E-Mail Removed), 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.

 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      09-04-2006
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.VisualBasic.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 ((E-Mail Removed), 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.
>



 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      09-04-2006
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.VisualBasic.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 ((E-Mail Removed), 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.
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-04-2006
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.WriteLine("s is numeric")
End If
s = "2006/9/1"
If IsDate(s) Then
Console.WriteLine("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.IsNumeric(text1))
{
Console.WriteLine("s is numeric");
}
text1 = "2006/9/1";
if (Information.IsDate(text1))
{
Console.WriteLine("s is date");
}
}

3) Click on the "IsNumeric" function to navigate to its source. You will
learn that it's located in Microsoft.VisualBasic.CompilerServices.Versioned
as a static method, so you can reference Microsoft.VisualBasic.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 ((E-Mail Removed), 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.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-04-2006
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.IsNumeric(s))
{
Console.WriteLine("s is numeric");
}
s = "2006/9/1";
if (Information.IsDate(s))
{
Console.WriteLine("s is date");
}
}

Previously I'm not checking that option, so the variable "s" has a generic
name "text1".


Regards,
Walter Wang ((E-Mail Removed), 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any IsNumeric in C#? Steve Kershaw ASP .Net 10 02-03-2012 03:27 AM
IsNumeric C# equivalent Stephan Bour ASP .Net 12 01-26-2012 12:48 PM
Name 'IsNumeric' is not declared??? David Lozzi ASP .Net 4 12-07-2004 01:35 AM
IsNumeric Function =?Utf-8?B?TXJNaWtl?= ASP .Net 5 11-29-2004 02:51 PM
Isnumeric and importing vb functions martin ASP .Net 3 07-19-2004 11:41 AM



Advertisments