Please see my other MVC articles.
Using Custom Validation within a View
While MVC provides many robust attributes within a Model to satisfy many validation scenarios, some situations exist which require custom logic to validate a user’s input.
This article will illustrate how to implement your own routines to validate user input.
First, create a new class which contains a “using System.ComponentModel.DataAnnotations,”inherits “ValidationAttribute,” and has a similar signature.
Now, to tie the custom validation class to the Model, you must add the following attribute.
When the user attempts to submit the form, your custom validation routine will warn the user should their input violate your business rules.