Then add a new SQL Server database named User Db to the App_Data folder and create a table - User Profile.The User Profile table has columns as shown in the following figure: The User Profile table As you can see from the above model class, the User Profile table consists of eight columns, viz.

validating text files-43validating text files-27validating text files-9

NET Entity Data Model to the project so that you get the User Profile entity class as shown above. ")] public string Last Name { get; set; } [Display Name("Email :")] [Required] [Email Address(Error Message="Invalid Email")] public string Email { get; set; } [Display Name("Profile :")] [String Length(500, Error Message = "Bio must be less than 500 characters!

In this example, you will validate all of the columns except Id, using various data annotation attributes. NET class (POCO) then you can directly decorate its properties with data annotation attributes. ")] public string Bio { get; set; } [Display Name("Age :")] [Required] [Range(18,100)] public int Age { get; set; } [Display Name("Blog URL :")] [Required] [Url(Error Message = "Invalid URL! ")] public string Phone { get; set; } } } The User Profile Metadata class contains property definitions for First Name, Last Name, Email, Bio, Age, Blog Url and Phone.

However, in this case our model class is an Entity Framework class. ")] public string Blog Url { get; set; } [Display Name("Phone :")] [Required] [Regular Expression(@"((\(\d{3}\) ? Notice the attributes that are used to decorate these properties.

Strategies and approaches for form-field validation in JSF 2.0.

See for the complete tutorial series, associated code, exercises, and exercise solutions.

You can also download PDF files of each lecture, for saving or printing.

Please email [email protected] info on how to arrange customized courses on JSF 2.2, Prime Faces, Java 8, Android development, Hadoop, and other Java EE topics onsite at YOUR location.

All of the above attributes also allow you to specify an error message that is displayed in the event of an error.

If an error message is not specified, a default error message is displayed.

Now that you have some idea about data annotation attributes, let's develop a simple ASP.

NET MVC application that makes use of these attributes for data validation. NET MVC project and select the Empty project template.