ASP.NET data annotations: how to check a list of strings?

Data annotations for validating an incoming model in MVC:

public class ValidNumber
{
    [RegularExpression(@"^\d+$", ErrorMessage = "*")]
    public string number { get; set; }
}

Do I need to create my own class to test, List<string>or can I do something like this? What code could I write in C # to add a Regex checker for a list of strings?

public class ValidNumberList
{
    [RegularExpression(@"^\d+$", ErrorMessage = "*")]
    public List<string> numbers { get; set; }
}
+3
source share
1 answer

it explains how to create a custom attribute and implement what you need MVC2 custom validation attribute

+3
source

Source: https://habr.com/ru/post/1789107/


All Articles