Regex validation on Tridion Schema fields

This is something I’ve wanted to do since we first started using Tridion at the RSPB – proper field validation. Turns out it’s ridiculously easy but I have never seen it in any Tridion documentation.

Chris Van Leeuwen blogged about it back in March 2009.

In your Schema, click on the Source tab and locate the field you’re interested in:

<xsd:element name="telephone" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>

Change it to:

<xsd:element name="telephone" minOccurs="0" maxOccurs="1">
<xsd:restriction base="xsd:normalizedString">
<xsd:pattern value="[0-9]+"/>

Notice the xsd:pattern tag – that’s where the magic happens. Also, bear in mind that you don’t need the ^& start and end characters in the pattern.

Unfortunately the message presented to the user if they don’t match the pattern is pretty horrible…fingers crossed SDL will fix that in an upcoming release.