SQL Server won't perform regular expression validation on XML column
Posted
by Kirk Broadhurst
on Stack Overflow
See other posts from Stack Overflow
or by Kirk Broadhurst
Published on 2009-01-21T21:55:52Z
Indexed on
2010/04/02
23:03 UTC
Read the original article
Hit count: 376
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.
© Stack Overflow or respective owner