John
John

Reputation: 1499

Extending the validation range expression to facilitate OR logic

In my class definition, lets say I want to allow the value 100 to be entered, in addition to 0-20 being valid, can this be acheived with a simple "or 100" logic to the expression?

>     [DisplayName("VAT %")]
>     [Range(0, 20)]
>     //[Range(100, 100)] tried this but cannot duplicate range expression
>     [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0.00}%")]
>     public decimal VAT { get; set; }

Upvotes: 1

Views: 29

Answers (1)

John
John

Reputation: 1499

OK I think its easy enough, i'll remove the "[Range(0, 20)]" from the class and simply add logic into the Validation() method server side. Don't think it can be done class side here unless maybe a regex

Upvotes: 1

Related Questions