Finding Entered Text is String or Numberic in C# by using Regex class
//Here i am writing code for Searching company either by using company id or company name
protected void Page_Load(object sender, EventArgs e)
{
if (IsNumber(txtDISCompanyId.Text))
{
DataSet ds = ListMatchingCompanies("", "", "", txtDISCompanyId.Text);
GetDIsCompanyInfo(ds);
}
else
{
DataSet ds = ListMatchingCompanies(txtDISCompanyId.Text,"","","");
GetDIsCompanyInfo(ds);
}
}
//This function will return either true or false. If the given text is numeric it will return true. else it will return false(entered text is string)
bool IsNumber(string text)
{
Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
return regex.IsMatch(text);
}