This article explains how to use the Custom Data Annotations Attribute in MVC 4.
Data Annotations Validation in MVC can be done using Data Annotations that are applied to both the client and server side. Data Annotation attributes are used to validate the user inputs when posting the form. All the Data Annotation attributes like Required, Range are derived from the ValidationAttribute class that is an abstract class. The ValidationAttribute base class lives in the System.ComponentModel.DataAnnotations namespace. This article is showing how to create a custom Data Annotations step by step:
Step 1
Create a New MVC 4 Application. Step 2
Select Razor View Engine. Step 3
Here I am showing Email validation on the Employee Registration Form. Select the Model Folder then select Add New Item -> Add New Class CustomEmailValidator.cs. Here we need to inherit the ValidationAttribute and need to override the IsValid method. CustomEmailValidator.cs
Now run the application:
ASP.NET MVC 5: A Beginner’s Guide