C# 正则表达式数字匹配

        /// 
        /// 带小数点数字匹配
        /// 
        /// 
        /// 
        public static bool IsNumber(string input)
        {
            string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\d+)?$";
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern);
            return regex.IsMatch(input);
        }

        /// 
        /// 数字匹配
        /// 
        /// 
        /// 
        public static bool IsWholeNumber(string strNumber)
        {
            System.Text.RegularExpressions.Regex g = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$");
            return g.IsMatch(strNumber);
        }

你可能感兴趣的:(正则表达式,c#)