本文共 1035 字,大约阅读时间需要 3 分钟。
////// 判断一个字符串是否是正整数 /// /// ///public static bool IsInteger(string s) { string pattern = @"^\d*$"; return System.Text.RegularExpressions.Regex.IsMatch(s, pattern); } /// /// 判断一个字符串是否为合法数字(0-32整数) /// /// 字符串 ///public static bool IsNumber(string s) { return IsNumber(s, 32, 0); } /// /// 判断一个字符串是否为合法数字(指定整数位数和小数位数) /// /// 字符串 /// 整数位数 /// 小数位数 ///public static bool IsNumber(string s, int precision, int scale) { if ((precision == 0) && (scale == 0)) { return false; } string pattern = @"(^\d{1," + precision + "}"; if (scale > 0) { pattern += @"\.\d{0," + scale + "}$)|" + pattern; } pattern += "$)"; return System.Text.RegularExpressions.Regex.IsMatch(s, pattern); }
转载地址:http://udmkz.baihongyu.com/