Field Validation Examples using Regex

Document created by Matthias_Walter Employee on Oct 3, 2018
Version 1Show Document
  • View in full screen mode

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 skybow rich forms as add-in but as well in solution studion 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

  1. Select the field you want to validate (any type not just single line of text)
  2. Open the validation expression builder in the BEHAVIOUR tab
  3. Switch the expression mode to "Function code" (which will accept multi line JS code)
  4. Add your validation logic that returns true or false. Use regex example from the list below or build your own here: https://regexr.com/ 
  5. 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,3})+$/;
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;
1 person found this helpful

Attachments

    Outcomes