Friday 17 February 2012

SharePoint 2010 Fields Validation

In SharePoint 2007 we have many issues with field validation when we add a new item to the list. So I solved it with JavaScript and I solved it with InfoPath Forms but it has never been easy.

In SharePoint 2010 we have great tools to perform field validation on the page without spending hours.

The first option is very intuitive. You can set the basic validation using the usual calculated fields functions during the creation of your field. You can use Excel functions just like I used it in the picture below to find out if some text appears in the field value or not. You can also build any other validation you want.



The User description field will show your users explanation about the content you want to see in the field. It will appear in red text under your field, like the example below.



Here are a few examples of field validation functions:

E-mail validation:

=AND((FIND(“@”,[E-mail filed])<>0),( FIND(“.”,[E-mail filed])<>0))

The AND function allows you to check more than one condition.

Today date validation:

=[Date field]>Today()

The second way to perform field validation is to edit the list forms using the InfoPath application.

This gives you really powerful abilities to edit your list forms. If you choose this method you’ll have much more options to design and validate your fields. For example: you can change the color of your field if it has not passed validation.

So, how do we do it?

Enter your list and click the “Customize Form” link. This link will open the InfoPath application (so make sure InfoPath is installed at your machine first). This button will design the “New”, “Edit” and “Design” forms but you will need to design it only once.



When the InfoPath form is opened you will see all the fields of your list at the left side of the window and you can add these fields to the form.

Let’s create some validation! Choose the field you want to validate and click the “Add Rule” button on the Ribbon.



Then click the “New” button and create a new Validation rule. You can also add a formatting rule to change the design of your fields that based on similar conditions. This is the “Conditional Formatting”, just a little redesigned.

Add a new validation rule. Click on “None” link under the “Condition” title to create new conditions.







Now it’s time to publish the form back to our SharePoint list. This is very easy to do. Just press the “File” option in the Ribbon and press the big “Quick Publish” button. That’s all. Now you have this validation in your SharePoint list forms.



No comments:

Post a Comment