用于C#中十进制数字验证的正则表达式 [英] Regex for decimal number validation in C#
本文介绍了用于C#中十进制数字验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要正则表达式,允许正负范围的小数位值
I need regular expression which allows positive as well as negative range decimals values
像 .89
, -1000
, 0.00
, 0
, 300
,.....
like .89
, -1000
, 0.00
, 0
, 300
, .....
我的正则表达式为 ^ \d * \。?\ d *
问题是当您输入特殊字符如 $
,!
, *
表示接受这些字符。
Problem is that when you entered special characters like $
, !
, *
then it accepts those characters.
推荐答案
如果您热衷于使用 regex
,则可以执行以下操作:
If you are keen on using regex
, the following will do:
^-?[0-9]*\.?[0-9]+$
这篇关于用于C#中十进制数字验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文