Reputation: 1747
How can I set a ViewModel to accept only specific values with a data annotation?
For example, I only want the input values from a form to be 2 or 4.
I'm looking for something like [Range(2, 4)]
, but that still accepts numbers in between. I want to list the specific numbers to accept.
[Required]
public int NumberParticipants { get; set; }
Also looking for the same thing with strings.
Upvotes: 0
Views: 86
Reputation: 2399
[RegularExpression("^(2|4)$", ErrorMessage = "Please enter 2 or 4")]
Upvotes: 1