Using Regular Expressions in SharePoint Lists

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):

    1. Within your SharePoint list, in the ribbon, click List
    2. In the Customize List group, click Customize Form
    3. Within the InfoPath Designer, in the Fields pane to the right, click the field for which you want to set up a regular expression
    4. In the ribbon, in the Rules group of the Home tab, click Manage Rules
    5. In the Rules pane, click the New list, and then click Validation
    6. Below the Condition header, click the None link
    7. In the Condition dialog, change the second drop-down list value to is not blank
    8. Click the And button to the right
    9. For the second condition, change the second drop-down list value to does not match pattern
    10. Change the third drop-down list value to Select a pattern
    11. In the Standard patterns area, click Custom pattern
    12. In the Custom pattern box, type [0-9a-zA-Z]{6}

Defining a Custom Pattern

    1. In the Data Entry Pattern dialog, click OK

Setting a Data Validation Rule

  1. In the Condition dialog, click OK
  2. In the Rules pane, in the ScreenTip box, type a validation tip (for example, Must enter six-character alphanumeric)
  3. Save the form template locally (a requirement for InfoPath Designer)
  4. Press CTRL+SHIFT+Q to publish the form back to the list
  5. Click OK after the form template is published successfully

3 thoughts on “Using Regular Expressions in SharePoint Lists

Leave a Reply

Your email address will not be published. Required fields are marked *