开发者

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

开发者 https://www.devze.com 2023-02-06 11:47 出处:网络
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 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

精彩评论

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