




Applies to version: 2016.1; Author: Szymon Patacz
When registering workflow instances, it might be beneficial to make sure that certain data is always saved in the same format and adheres to a specific standard, regardless of who is entering the data.
We can force users to save information like postal codes and bank account numbers in a specific format. We do this by using the option to validate text entered into form fields by means of a regular expression.
Note: This article covers the validation of data that is being entered into the form, if you wish to learn how to display already existing values of form fields in a certain format on your SharePoint form – please go here: Formatting data displayed on the form by Szymon Patacz
Postal code
The postal codes format used in Poland is made up of 5 digits, separated by a hyphen ‘–‘ that appears between the 2nd and 3rd digit. We can verify that the character string entered into the form is in the correct format by adding RegEx validation to the form field, like so:
This regular expression will prevent saving any values entered into the field unless they match to the following format: ‘xx-xxx‘ where ‘x‘ represents any digit. If a non-viable value is entered into the field, the error message specified in the Regex validation section will be displayed – in this case it will display ‘[form field name] Invalid format‘ and also provide a link to a site listing Polish postal codes.
If a field is expecting to receive postal codes from different countries, we can also include RegEx for foreign postal codes, separating every new expression with the ‘ | ‘ sign. So for example, the full regular expression which will allow both Polish and German (5 digits) postal codes to be entered, will look like this:
(\d{2}-\d{3})|(\d{5})
This regular expression will allow the form field to accept postal codes in 12-345 or 12345 formats.
Bank account number
In Poland, digital account numbers are made up of 26 digits. To make it more pleasant to the eye, the block of digits is spaced out according to the following format:
XX XXXX XXXX XXXX XXXX XXXX XXXX
When entering this number manually, we can implement a system for checking whether the field contains exactly 26 digits, or 26 digits separated by spaces.
The regular expression will look like this:
(\d{26})|((\d{2} )(\d{4} ){5}\d{4})
Analogously as with postal codes, if we need to add expressions for formats used in other countries, we can add the onto the existing regular expression – with the ‘ | ‘ sign dividing individual formats.
This is the quickest way to validate data entered into form fields on the SharePoint form. An additional advantage of this method is that the entered value is validated (and if necessary, an error message is displayed) as soon as it is typed/pasted into the form field.