Enforce regex pattern validation by role

This example uses the ISROLE and INVALID functions to programmatically validate a text field against a regex pattern based on the user role. This could be used to force field user comments to be more succinct while allowing manager comments to be more detailed.

ON('validate-record', function(event) {
  if (ISROLE('Standard User', 'Field Crew')) {
    var str = $name;
    var re = /^[A-Za-z]{5}$/;
    var result = re.test(str);
    if (result == false) {
      INVALID('The value for the Name field must be exactly 5 characters');
    }
  }
});