The [Display Name] attribute is used to specify a friendly name for the property under consideration.

This friendly name is used by HTML helpers such as Html. If you don't use the [Display Name] attribute a property name will be used for display purpose.

javascript validating phone number field-65javascript validating phone number field-53javascript validating phone number field-4

The [Metadata Type] attribute accepts the type of the class that is supplying metadata information to the User Profile class (User Profile Metadata in this case).

Now, add a new controller in the Controllers folder and name it Home Controller.

In this example you validate the Phone property with a regular expression for US phone numbers.

At this stage, the User Profile Metadata class is just an independent class in your project.

The first version is used when you make a GET request and the other is used when the form is submitted by the end user.

The second Index() method accepts User Profile as a parameter. The Is Valid property returns false if any of the properties contain invalid values.

However, in this case our model class is an Entity Framework class.

Since the data model class is automatically created for you by the Visual Studio designer it is not recommended to modify the same class file.

The [Range] attribute checks whether a property value falls between a minimum and a maximum value.