Text Columns with Regular Expression Validation
SharePoint does not support validating values, and it is not required in some cases. However, if you try to build complex business processes based on entered data, it is critical to validate that users input correct data in the fields.
This article describes how to create an Email text field that validates regular expressions without any codes.
For this task, you need to download and install Virto Custom Mask and Unique Field Validation. This multi-purpose component allows you to create custom fields in design mode and check fields for unique criteria within the current list, site or site collection framework.
To start, create a new list where you will be creating the new text field or go to an existing list. Then go to Settings > Create Columns.
Title the name of your new field as “Email”. If you have Virto Custom Mask and Unique Field Validation installed, a list of column types will be available. Select “Virto Custom Mask”.
Once column type is selected, visual field editor will be available. It consists of several blocks.
Block 1 defines unique scope, automatic field case and separator between elements.
Block 2 contains mask preview which is refreshed automatically, but you can also refresh it manually by clicking the “Refresh” button.
Block 3 allows adding, deleting and adjusting mask elements.
Now, let’s add a text block. In order to do this, select “Text” in the “Select mask item type” section and click “Add”. You will see the following picture as a result.
This block is not editable by default. Check the “Editable” box to change this setting.
You need to define the Pattern for this block. This can be done by using regular expressions that will check if entered data is in the format of an email address.
You can use the following regular expressions (please see https://www.regexlib.com/REDetails.aspx?regexp_id=711):
^((?>[a-zA-Zd!#$%&’*+-/=?^_`{|}~]+x20*|»((?=[x01-x7f])[^”\]|\[x01-x7f])*”x20*)*(?<angle><))?((?!.)(?>.?[a-zA-Zd!#$%&’*+-/=?^_`{|}~]+)+|”((?=[x01-x7f])[^”\]|\[x01-x7f])*”)@(((?!-)[a-zA-Zd-]+(?<!-).)+[a-zA-Z]{2,}|[(((?(?<![).)(25[0-5]|2[0-4]d|[01]?d?d)){4}|[a-zA-Zd-]*[a-zA-Zd]:((?=[x01-x7f])[^\[]]|\[x01-x7f])+)])(?(angle)>)$
You can define the text color in addition to basic settings. The following is the result of the template:
The field for inputting email address with validation settings is ready to use. Click “OK” to add this field to the list.
You will now have the menu options to create, edit and view forms of the list containing the new form for inputting email addresses.
Here are several screenshots of the created mask:
A library of regular expressions for new masks can be found at: www.regexlib.com.