/// 判斷字符串是否是數(shù)字?
public static bool IsNumType(this string str, NumType nt) {?
string matchString = "";?
switch (nt)? {?
case NumType.NonNegativeInt:?
//非負(fù)整數(shù)(正整數(shù) + 0)?
matchString = @"^[1-9]+[0-9]*$|^0$";?
?break;?
?case NumType.PositiveInt:?
//正整數(shù)?
matchString = @"^[1-9]+[0-9]*$";?
break;?
case NumType.NonPositiveInt:?
//非正整數(shù)(負(fù)整數(shù) + 0)?
matchString = @"^-[1-9]+[0-9]*$|^0$";?
break;?
case NumType.NegativeInt:?
//負(fù)整數(shù)?
matchString = @"^^-[1-9]+[0-9]*$";?
break;?
case NumType.Int:?
//整數(shù)?
matchString = @"^-?[1-9]+[0-9]*$|^0$";?
break;?
case NumType.NonNegative:?
//非負(fù)數(shù)(正數(shù) + 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:?
//正數(shù)?
matchString = @"^(0\.0*[1-9]+[0-9]*$|[1-9]+[0-9]*\.[0-9]*[0-9]$|[1-9]+[0-9]*$)";?
break;?
case NumType.NonPositive:?
//非正數(shù)(負(fù)數(shù) + 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:?
//負(fù)數(shù)?
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);?
?}