ASP.NET Data Annotation: How to validate a List of string?
Data annotation to validate an inbound model in MVC:
public class ValidNumber
{
[RegularExpression(@"^\d+$", ErrorMessage = "*")]
public string number { get; set; }
}
Would I need to create my own class to validate a List<string>
or can I do something like this? What code could I write in C# to add a Regex validator for a list of string?
public class ValidNumberList
{开发者_运维百科
[RegularExpression(@"^\d+$", ErrorMessage = "*")]
public List<string> numbers { get; set; }
}
here is explained how to create custom attribute and implement what you need Custom Validation Attribute MVC2
精彩评论