开发者

need a regex for a positive max 2 digits after . floating number

开发者 https://www.devze.com 2023-01-18 13:31 出处:网络
Hi I need a C# regex fo开发者_运维问答r a positive floatin no with maximum 2 digits for decimals. Also the regex should check for letters and alphanumerical chars (not allowthem) and not allow also th

Hi I need a C# regex fo开发者_运维问答r a positive floatin no with maximum 2 digits for decimals. Also the regex should check for letters and alphanumerical chars (not allow them) and not allow also the input value to be empty (0 characters). Thanks


^[+]?[0-9]+([.][0-9]{1,2})?$

This will force it to have either a + or nothing at the start, followed by at least 1 number, then optional (decimal followed by 1 or 2 numbers)

For others, yes, I know of \d, :digit:, using \., etc. I just prefer using [0-9] and [.], it makes them stand out easier for me.

0

精彩评论

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