3

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; }
}
Kris Ivanov
  • 10,476
  • 1
  • 24
  • 35
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205

1 Answers1

3

here is explained how to create custom attribute and implement what you need Custom Validation Attribute MVC2

Community
  • 1
  • 1
Kris Ivanov
  • 10,476
  • 1
  • 24
  • 35