Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 MinimumValueAttribute exist for validation with only a lower extent?

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

like image 781
Maxim Zaslavsky Avatar asked Jul 04 '10 22:07

Maxim Zaslavsky


2 Answers

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

like image 98
Felix Avatar answered Sep 28 '22 20:09

Felix


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

"^\$?\d+(\.(\d{2}))?$"
like image 26
Chase Florell Avatar answered Sep 28 '22 22:09

Chase Florell