SQL Server won't perform regular expression validation on XML column
- by Kirk Broadhurst
Hi
I have an XML column in my table which contains this xsd snippet:
<xsd:element name="Postcode" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="^[0-9]{4}$" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
The regular expression should require a string containing 4 numerical digits. It validates perfectly in Visual Studio and is a correct regular expression.
SQL Server, on the other hand, won't accept it. The error message I receive is:
XML Validation: Invalid simple type value: '1234'. Location: / * : Donor[1]/*:Postcode[1].
I have an email address regex working fine, but can't get this simple numerical regex to work.