isnumeric

jagguy
jagguy used Ask the Experts™
on
is there an isnumeric function in silverlight?
I cant find it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jaime OlivaresSoftware Architect
Top Expert 2008

Commented:
you can use int.TryParse() or float.TryParse() like

int dummy;
if (TryParse(someString, out dummy))
{
     // it is numeric
}

you can do the same with float or double, or any other numeric type.
Indeed TryParse will convert the string to a numeric value (dummy). If you just want to test if it is numeric, you have to use a dummy variable.
Senior Developer
Commented:
Below is possible implementation if you need to write a function (still uses jaimie's approach) from
http://www.vbforums.com/archive/index.php/t-282514.html:


private bool IsNumeric(object ValueToCheck)
{
double Dummy = new double();
string InputValue = Convert.ToString(ValueToCheck);
 
bool Numeric = double.TryParse( InputValue , System.Globalization.NumberStyles.Any , null , out Dummy);
 
return Numeric;
}

Open in new window

Jaime OlivaresSoftware Architect
Top Expert 2008

Commented:
double Dummy = new double();
shall be just:
double Dummy;
anarki_jimbelSenior Developer

Commented:
My apologies - you are right!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial