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; }
}
1
  • you can inherit from ValidationAttribute Class and implement your own IsValid Method Commented Jan 31, 2011 at 22:54

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.