开发者

ASP.NET MVC 2 and ComponentModel.DataAnnotations Validation: minimum value attribute

开发者 https://www.devze.com 2023-01-06 05:14 出处:网络
I\'m decorated a ViewModel in my ASP.NET MVC 2 site with System.ComponentModel.DataAnnotations validation attributes. For one of my fields, named Price, I want to validate that the value is not below

I'm decorated a ViewModel in my ASP.NET MVC 2 site with System.ComponentModel.DataAnnotations validation attributes. For one of my fields, named Price, I want to validate that the value is not below some extent, in this case 0.

I know that RangeAttribute exists for validation with a lower and an upper extent, but does something like a Mi开发者_StackOverflow中文版nimumValueAttribute exist for validation with only a lower extent?

If not, I guess I'll just roll my own.


before you roll your own - try [Range(0.05, Double.MaxValue)]


Not sure if RegularExpression is the "best" solution, but you can give it a shot

"^\$?\d+(\.(\d{2}))?$"
0

精彩评论

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