正则判断是否是数字

        /// <summary>
        /// 判断是否为单精度数字
        /// </summary>
        /// <param name="str">比较字符串</param>
        /// <returns></returns>
        public static bool IsFloat(string str)
        {
            Regex regex = new Regex(@"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
            return regex.IsMatch(str);
        }

        /// <summary>
        /// 判断是否是Double类型
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsDouble(string str)
        {
            Regex regex = new Regex(@"^[+-]?\d*[.]?\d*$");
            return regex.IsMatch(str);
        }

 

posted @ 2020-09-21 10:44  恋上微笑的天使  阅读(3461)  评论(0编辑  收藏  举报