调节器表达式验证,以允许空白/空值和十进制/整数值 [英] Reguler Expression validation to allow blank/empty and decimal/integer values

查看:78
本文介绍了调节器表达式验证,以允许空白/空值和十进制/整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends

我需要一个允许以下内容的调节器表达式:

1)空白或空
2)十进制值
3)整数值


Hi Friends

I need a reguler expression that allows:

1) blank or empty
2) decimal values
3) integer values


[Required(ErrorMessage = "rate 1 is required")]
[RegularExpression(@"[0-9]*\.?[0-9]*$", ErrorMessage = "rate 1 is in numeric formate")]
public decimal Rate1 { get; set; }



请帮助我,以上表达式不允许使用空值.

谢谢



Please help me, the above expression is not allowing null values.

Thanks

推荐答案

",ErrorMessage = 比率1以数字形式表示")] 公用 十进制 Rate1 { get ; 设置; }
", ErrorMessage = "rate 1 is in numeric formate")] public decimal Rate1 { get; set; }



请帮助我,以上表达式不允许使用空值.

谢谢



Please help me, the above expression is not allowing null values.

Thanks


您在此处有Required属性.如果需要一个值,则不能为null.正则表达式与它无关.
You have the Required attribute on there. If a value is required it cannot be null. The regular expression has nothing to do with it.


因此,您允许(我假设使用前导和尾随空格)
1.只有空格的行,零到任意数目
2.普通整数
3.在小数部分前有小数部分和可选部分的数字

这些单个部分的正则表达式为:
1. ^ \ s *
So, you allow (I assume with leading and trailing spaces)
1. lines of only spaces, zero to any number of them
2. plain integral numbers
3. numbers with decimal part and optional part before the decimal part

The regex for these individual parts is:
1. ^\s*


这篇关于调节器表达式验证,以允许空白/空值和十进制/整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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