十进制数验证 [英] validation for decimal numbers

查看:90
本文介绍了十进制数验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的MVC项目中有一个名为Scheme的模型。在那个模型中我有一个字段Period。这是一个十进制值。我想验证这个字段,如果在deciml点之后的值应该在范围内(1,13)。



我该怎么办呢



请帮助我

Hi,

I have a model named Scheme in my MVC Project. in that model i have a field "Period". that is a decimal value. i want to validate this field like, the value after the deciml point should be in the range (1,13).

how can i do that

please help me

推荐答案

你没有说清楚这一点,但似乎你正在对此十进制 值更像版本号,格式为 [number]。[number] 。我知道你已经为自己的答案提供了信誉,但我不同意。



首先,你的正则表达式 [\ d ] {1,} \。[\ d] [0-3] {1} 有一些无关的语法。这是干净的等价物: \d + \.\d [0-3]



它会错误地匹配这些值:

1.00 1.20 1.21 1.22 ,< b> 1.73 , 1.90 ,...

它将错误地错过这些值:

1.1 1.2 1.3 ,...



这是你真正想要的:

^ \d + \。(0?[1-9] | 1 [0-3])
You don't state this clearly, but it seems that you are treating this "decimal" value more like a version number, in the format [number].[number]. I know you already gave yourself credit for the correct answer, but I have to disagree.

First of all, your regex [\d]{1,}\.[\d][0-3]{1} has some extraneous syntax. Here's the clean equivalent: \d+\.\d[0-3]

It will incorrectly match these values:
1.00, 1.20, 1.21, 1.22, 1.73, 1.90, ...
It will incorrectly miss these values:
1.1, 1.2, 1.3, ...

This is what you really want:
^\d+\.(0?[1-9]|1[0-3])



我得到了解决方案



i got the solution

[RegularExpression(@"[\d]{1,}\.[\d][0-3]{1}", ErrorMessage = "Number after decimal point should not greater than 12")]


这篇关于十进制数验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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