Validation of content in SDL Tridion can be accomplished using the UI, but some input just can’t be validated with the default options in the Tridion UI. This article explains how you can improve content validation using Regular Expressions!
The SDL Tridion CMS stores content in XML. These XML’s are structured using XML Schema’s (XSD) which can be constructed using the Tridion UI. The Tridion UI allows developers to create structured content blocks (or components) including;
- Literal content
- Rich text
- Date/Time
- Complex type (e.g. embeddable schema)

Example of a Tridion Schema
The default input validation, however, is limited to default values and required fields. Using the power of regular expressions we can force our disobidiant users to enter text according to some constraints!
I’ll explain a regular expression validation using the example of a time only field. To start, switch to “Source” tab to view the underlying XSD Tridion generates for us. A typical XSD generated by Tridion is shown below;
<xsd:schema targetNamespace="uuid:1FBE4459-87D3-465A-B98E-E7A9F77D7FF9" ...>
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels>
<tcm:Label ElementName="time" Metadata="false">time</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"/>
<xsd:element name="Content">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="time" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
This example schema contains only one field name “time” which is a XSD normalizedString. To add the Regular expression check modify the red line schema as follows:
<xsd:element name="To" minOccurs="1" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:normalizedString">
<xsd:pattern value="\d{2}:\d{2}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Note that the type attribute is removed from the element tag.
For those who have not master the Vulcan Mind Melting technique of writing regular expression; the regular expression \d{2}:\d{2} means input should contain two digits (\d{2}) followed by a colon (:) which is followed by another two digits (\d{2}). More info about regular expression can be found at regular-expressions.info.
Now when a user enters an invalid value according to your regular expression, the user is presented by an error message:

Tridion Regular Expression Error
Which is hardly any use to your users; but hey your just a developer :). But, seriously: use with care, your users will hate you for it!
Tags: SDL Tridion
This is the professional blog of Christian van Leeuwen, Senior Consultant Web Strategy at Deloitte Consulting. I like talking about topics such as front-end development, interaction design and web development.
November 24th, 2009 at 08:31
hi, i have multivalue field in Tridion 2009,
xsd e.g <xsd:element name=”time” minOccurs=”0″ maxOccurs=”unbound
i want to restrict maxOccurs=6 but tridion do not support it.
if i manually change unbound to “6 tridion make it single value. some kinda but in Tridion.
Could you tell me alternate way to restrict multivalue element to a limit.
Thanks
November 25th, 2009 at 11:28
@kumar; your approach setting
maxOccurswould be my first guess. Unfortunately there is no clean way of doing this. Two alternate approaches are:Option 1) Create a embedded schema with 6 fields (time1, time2, ect). The downside to this users always see all three fields.
Option 2) Use a
maxOccurs="unbound"field and add force the restriction logic in your templates and add a descriptive text to your label (f.e. “time (MAX 6)”).