开发者

Regular Expression for percents (with % sign) in ASP.Net RegEx Validator

I need a regex for the ASP.Net (4) Regex Validation control. It needs to be a RegEx validator to support other dynamic beh开发者_运维问答aviors outside the scope of this post..

I was using the following, but it fails if the user enters the % sign following the number (which is a req of my spec):

^(100(?:\.0{1,2})?|0*?\.\d{1,2}|\d{1,2}(?:\.\d{1,2})?)$

I tried adding an atomic group of ^(?>%?) at the end, with no luck, after reading the excellent post

Regular expression greedy match not working as expected

Does anyone have any ideas?


Try this

^(100(?:.0{1,2})?%?|0*?.\d{1,2}%?|\d{1,2}(?:.\d{1,2})?%?)$


try this one instead:

^0*(100(\.00?)?|[0-9]?[0-9](\.[0-9][0-9]?)?)%?$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜