/// 判断字符串是否是数字
public static bool IsNumType(this string str, NumType nt) {
string matchString = "";
switch (nt) {
case NumType.NonNegativeInt:
//非负整数(正整数 + 0)
matchString = @"^[1-9]+[0-9]*$|^0$";
break;
case NumType.PositiveInt:
//正整数
matchString = @"^[1-9]+[0-9]*$";
break;
case NumType.NonPositiveInt:
//非正整数(负整数 + 0)
matchString = @"^-[1-9]+[0-9]*$|^0$";
break;
case NumType.NegativeInt:
//负整数
matchString = @"^^-[1-9]+[0-9]*$";
break;
case NumType.Int:
//整数
matchString = @"^-?[1-9]+[0-9]*$|^0$";
break;
case NumType.NonNegative:
//非负数(正数 + 0)
matchString = @"(^(0\.0*[1-9]+[0-9]*$|[1-9]+[0-9]*\.[0-9]*[0-9]$|[1-9]+[0-9]*$)|^0$)";
break;
case NumType.Positive:
//正数
matchString = @"^(0\.0*[1-9]+[0-9]*$|[1-9]+[0-9]*\.[0-9]*[0-9]$|[1-9]+[0-9]*$)";
break;
case NumType.NonPositive:
//非正数(负数 + 0)
matchString = @"(^-(0\.0*[1-9]+[0-9]*$|[1-9]+[0-9]*\.[0-9]*[0-9]$|[1-9]+[0-9]*$)|^0$)";
break;
case NumType.Negative:
//负数
matchString = @"^-(0\.0*[1-9]+[0-9]*$|[1-9]+[0-9]*\.[0-9]*[0-9]$|[1-9]+[0-9]*$)";
break;
default:
break;
}
return Regex.IsMatch(str, matchString, RegexOptions.IgnoreCase);
}