C#正则表达式小数范围验证 [英] C# regex decimal range validation

查看:332
本文介绍了C#正则表达式小数范围验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要一个正则表达式来验证从-12.0到+12.0的小数值范围



搜索给了很多正则表达式,但没有任何效果。任何人都有正确的rgex请帮助。



提前谢谢

Hi all,

I need a regular expression to validate decimal value ranges from -12.0 to +12.0

Search gave many regex but nothing worked. Anybody having correct rgex for this please help.

Thanks in advance

推荐答案

做这种验证使用正则表达式并不是最简单的方法。通常,您将字符串转换为其数值并与允许范围的范围进行比较。



如果您真的想要正则表达式,则需要:

Doing this kind of validation with a regexp is not the simplest way. Usually, you convert the string to its numerical value and compare to the bounds of the allowed range.

If you really want a regexp, you need to:
- accept the optional sign character, followed by
        - the digit 1 followed by the digit 2 followed by an optional . followed by any number of 0
        - or a single digit or the pair 10 or the pair 11 followed by an optional . followed by any digit(s)


这篇关于C#正则表达式小数范围验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆