IsNumeric function in C#?

Poster
Posted by Poster under C# category on | Views : 12611
You can use following

Microsoft.VisualBasic.Information.IsNumeric("5") to return true or false.

OR

You can write your own function that will return true/false.

public static bool IsNumeric(string inputString)
{
return Regex.IsMatch(inputString, "^[0-9]+$");
}

Comments or Responses

Posted by: Deeraj on: 11/21/2008 Level:Starter | Status: [Member]
This is another way:

bool test = false;
string s = "1";
int i = 0;
test = Int32.TryParse(s, out i);
if (test)
Debug.Print(i.ToString());

HTH

Dheeraj.

Login to post response