Field Validation Examples using Regex
The SharePoint out-of-the-box field validation is very limited and you can't use regex to validate the value entered in the form.
Using teamsware rich forms as add-in but as well in solution studio you can configure a validation on each form field and use the power of regex (or any other way using placeholders or JavaScript).
How to configure
- Select the field you want to validate (any type not just single line of text)
- Open the validation expression builder in the BEHAVIOUR tab
- Switch the expression mode to "Function code" (which will accept multi line JS code)
- Add your validation logic that returns true or false. Use regex example from the list below or build your own here: https://regexr.com/
- Don't forget to set a validation text in the "Validation Text" field in the ribbon that should be shown if the validation fails
Examples
Select the field you want to check from the fields list on the right (should be like [[InternalFieldName]])
Email address
if([[Email]]!==""){
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/;
return mailformat.test([[Email]]);
} else
return true;
IP address
if([[IPAddress]]!==""){
var ipformat = /\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/ig;
return ipformat.test([[IPAddress]]);
} else
return true;
Credit Card (MasterCard)
if([[MasterCard]]!==""){
var mcformat = /^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/g;
return mcformat.test([[MasterCard]]);
} else
return true;
US phone number
if([[BusinessPhone]]!==""){
var usphoneformat = /(?:\d{1}\s)?\(?(\d{3})\)?-?\s?(\d{3})-?\s?(\d{4})/g;
return usphoneformat.test([[BusinessPhone]]);
} else
return true;
Related Articles
Teamsware Studio Update 18.01.2024
New Features M365 Actions M365 actions allows you to build powerful workflows related to Microsoft 365 Groups, OneNote, Planner, Teams in Scheduled/Triggered Actions Bug fixes & improvements Modern Forms Version 1.3.43 Fixed Footnotes/Endnotes in the ...
Action: Update meetings
Update meetings action allows to update properties of the specified online meeting in Microsoft Teams and in Outlook as well. It allows to update properties of a single meeting and a series of meetings. Example of Upgrade meetings action ...
Teamsware Studio Update 09.11.2023
Bug fixes & improvements Modern Forms Version 1.3.37 Fixed opening form in the panel when redirecting from the Home page to the List using the left navigation Fixed aggregation calculations (Totals) in the sublist component for grouped list view ...
Teamsware Studio Update 24.10.2024
New features Add Invite Guest user action Added Invite Guest User to modern Forms, List Actions, Automation Actions Bug fixes & improvements Modern Forms Version 1.3.67 Added option in Field configuration panel to customize Field label on the form ...
Action: Generate document
Generate document action allows you to generate documents based on a standard Microsoft Word file filled with SharePoint list data. For more information about Action Builder read Action Builder Introduction article. For more information about ...