我必须编写一个匹配以下模式的正则表达式,它应该匹配十进制值,其格式如下所示。
- +100.00
- -100.00
- .6777
- 0.45555
- the normal entry of the decimal values like 100 100.25 100.... and also the decimal points should be restricted 6 decimal positions.
这是我到目前为止写的正则表达式:
return Regex.IsMatch(value, "^((\\+|-)(\\d*))+((\\.|,)\\d{0,5})?$");
目前,如果值类似于 +100
或 -100
,则正则表达式匹配。如果我输入像 100
这样的值,它不会被接受,如果我以 .899
这样的小数点开头,则 IsMatch
返回 false。
最佳答案
关于c# - 什么正则表达式将匹配限制为 6 个小数位的小数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5662703/