Enforcing Custom List Item Data Validation

Two approaches were considered for validating the Training Course SharePoint list items. One approach was to edit the standard NewForm.aspx and EditForm.aspx pages to add custom validation controls. However, editing standard SharePoint files is not an ideal solution because you lose some of the standard functionality that SharePoint provides, such as the standard appearance and behavior (look and feel) and built-in client side validations. Also, users can circumvent the validation by using the SharePoint Web services or Web-based Distributed Authoring and Versioning (WebDAV).

Another approach is to add custom list item event receivers to the list that holds the items that you want to validate. This approach enables you to use custom business logic that either allows or cancels the addition or editing of a list item. Also, as part of the cancellation process, you can specify custom error messages that appear in the standard error page.

Because standard list item fields provide only basic data types and essential field validations, adding custom validation through list item event receivers also allows you to include functions such as performing comparisons with other fields, validating formats, and validating an item's uniqueness. One drawback to this approach is that list item event receivers can be implemented only as server-side code. This approach is not appropriate when client-side validation is required.

For an example of custom validation, see The List Item Event Receivers.

Home page on MSDN | Community site