SoFunction
Updated on 2025-03-07

C# determines whether the string is int/double (instance)

Without further ado, please see the code

using ;
/// <summary>
/// Determine whether the string is int/double/// </summary>
public static bool IsIntOrDouble(string strNumber)
{
 Regex objNotNumberPattern = new Regex("[^0-9.-]");
 Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
 Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
 const string strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
 const string strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
 Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
 return !(strNumber) &&
  !(strNumber) &&
  !(strNumber) &&
  (strNumber);
}

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!