IsNumeric() hell

My blog has moved.
You can view this post at the following address:
http://www.osherove.com/blog/2003/9/14/isnumeric-hell-1.html
Published Sunday, September 14, 2003 10:14 PM by RoyOsherove
Filed under:

Comments

Sunday, September 14, 2003 8:18 PM by Doug Ferguson

# re: IsNumeric() hell

In the .NET Framework you can do a lot of string operations with RegEx.

A Google search on "isnumeric regex" turned up an example at:

http://www.aspalliance.com/olson/methods/IsNumeric.aspx
Monday, September 15, 2003 12:34 PM by Xavier Lazard

# re: IsNumeric() hell

I was going to say that many of the methods listed in the discussion would not take into account numbers written in an exponential format. However the methods listed in Doug Ferguson's link would.
Monday, September 15, 2003 2:45 PM by Phil

# re: IsNumeric() hell

I just reference the MS.VB dll, or you can use Double.TryParse().
Monday, September 15, 2003 4:02 PM by Chad Osgood

# re: IsNumeric() hell

I'm Chad from the Tulsa DNUG (also the recently enigmatic blogger), so I extend my appreciation for any value you derived from the discussion :)
Monday, September 15, 2003 5:42 PM by Xavier Lazard

# re: IsNumeric() hell

a possible Hybrid implementation:

public bool IsNumeric(object s)
{
if ( s is decimal )
{
return true;
}
if ( s is int )
{
return true;
}
if ( s is short )
{
return true;
}
if ( s is long )
{
return true;
}
if ( s is uint )
{
return true;
}
if ( s is float )
{
return true;
}
if ( s is ulong )
{
return true;
}
if ( s is ushort )
{
return true;
}
if ( s is char )
{
return (((char)s > 57 || (char)s < 48));
}
if (s is string)
{
System.Double OutputValue;
return System.Double.TryParse((string) s,
NumberStyles.Any | NumberStyles.AllowHexSpecifier | NumberStyles.AllowHexSpecifier,
CultureInfo.CurrentCulture , out OutputValue );
}

return false;

}
Friday, June 25, 2004 7:12 AM by janine

# re: IsNumeric() hell

thanks a mill for highlighting this - wasn't life so much simpler back in those classic asp days!
Sunday, July 04, 2004 6:36 AM by TrackBack

# looking for isnumeric in vb.net?

i was wondering why a vb.net class file was throwing up errors when i called the isnumeric function the other day. after some googling i found out from roy osherove's blog that you now need to import the microsoft.visualbasic to...