/// <summary>
/// 判斷是否是數字
/// </summary>
/// <param name="strNumber">要判斷的字符串</param>
/// <returns></returns>
public static bool IsNumber(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]*");
String strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+___FCKpd___0quot;;
String strValidIntegerPattern = "^([-]|[0-9])[0-9]*___FCKpd___0quot;;
Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
return !objNotNumberPattern.IsMatch(strNumber) &&
!objTwoDotPattern.IsMatch(strNumber) &&
!objTwoMinusPattern.IsMatch(strNumber) &&
objNumberPattern.IsMatch(strNumber);
}
/// <summary>
/// 判斷是否是int類型
/// </summary>
/// <param name="Value">要判斷的字符串</param>
/// <returns></returns>
public static bool IsInt(string Value)
{
return Regex.IsMatch(Value, @"^[+-]?/d*___FCKpd___0quot;);
}
/// <summary>
/// 判斷是否是數字
/// </summary>
/// <param name="Value">要判斷的字符串</param>
/// <returns></returns>
public static bool IsNumeric(string Value)
{
return Regex.IsMatch(Value, @"^[+-]?/d*[.]?/d*___FCKpd___0quot;);
}