c#正则表达式匹配整数和小数

c#中使用正则表达式需要加入using System.Text.RegularExpressions的引用

匹配整数的一种表达式:

Regex.IsMatch(inputerstr, "^([0-9]{1,})$")

其中Inputerstr是要匹配的字符串

这个表达式仅匹配整数,如果是整数形式返回true,否则为false

匹配小数格式的表达式:

Regex.IsMatch(inputerstr, "^([0-9]{1,}[.][0-9]*)$")

其中Inputerstr是要匹配的字符串

这个表达式仅匹配数字中有小数点格式的数字,如果是带有小数点格式的纯数字,返回true,否则为false。

原文地址:https://www.cnblogs.com/generalz/p/1890097.html