开发者

ASP.NET Data Annotation: How to validate a List of string?

开发者 https://www.devze.com 2023-02-07 23:45 出处:网络
Data annotation to validate an inbound model in MVC: public class ValidNumber { [RegularExpression(@\"^\\d+$\", ErrorMessage = \"*\")]

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

精彩评论

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