Using Regular Expressions in SharePoint Lists
*This blog post is outdated and no longer maintained*
Within SharePoint lists you can specify a formula that will validate the data in a specific column. When defining or editing the column, you can use the Column Validation section at the bottom of the settings page to enforce certain syntax. This article does a good job of illustrating how to use string functions in the Column Validation section.
If you are an old-timer like me, you might prefer to use regular expressions as a means for validating a text string. While regular expressions are not supported directly within the SharePoint list user interface, you can customize the form associated with the list and use regular expressions within the InfoPath Designer (assuming you have InfoPath Designer installed on your machine). As an example, if you had a column in your list that had to be exactly six characters in length and could only contain alphanumerics, you could implement regular expressions in the following way (using SharePoint Server 2010):
-
Within your SharePoint list, in the ribbon, click List
-
In the Customize List group, click Customize Form
-
Within the InfoPath Designer, in the Fields pane to the right, click the field for which you want to set up a regular expression
-
In the ribbon, in the Rules group of the Home tab, click Manage Rules
-
In the Rules pane, click the New list, and then click Validation
-
Below the Condition header, click the None link
-
In the Condition dialog, change the second drop-down list value to is not blank
-
Click the And button to the right
-
For the second condition, change the second drop-down list value to does not match pattern
-
Change the third drop-down list value to Select a pattern
-
In the Standard patterns area, click Custom pattern
-
In the Custom pattern box, type [0-9a-zA-Z]
13. In the Data Entry Pattern dialog, click OK
14. In the Condition dialog, click OK
15. In the Rules pane, in the ScreenTip box, type a validation tip (for example, Must enter six-character alphanumeric)
16. Save the form template locally (a requirement for InfoPath Designer)
17. Press CTRL+SHIFT+Q to publish the form back to the list
18. Click OK after the form template is published successfully