【问题标题】:How to give Data Annotation Validation for NOT NULL OR ZERO in MVC3 Regular Expression如何在 MVC3 正则表达式中对 NOT NULL OR ZERO 进行数据注释验证
【发布时间】:2012-01-25 16:12:03
【问题描述】:
[RegularExpression("", ErrorMessage = " Affordable fees cannot be Zero or Negative.")]
public decimal AffordablePayment { get; set; }
我需要 DataAnnotation Validation 中 ErrorMessage 的正则表达式。请帮帮我。谢谢!
【问题讨论】:
标签:
asp.net
asp.net-mvc
asp.net-mvc-3
asp.net-mvc-2
【解决方案1】:
[Range(0.01, double.MaxValue, ErrorMessage = "Affordable fees cannot be Zero or Negative.")]
public decimal AffordablePayment { get; set; }
【解决方案2】:
试试这个:
(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)