开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜