Reputation: 4900
I'm trying to validate an XML input against an XML Schema in SQL Server 2005 and I get an error when validating the e-mail:
Msg 6926, Level 16, State 1, Line 4
XML Validation: Invalid simple type value: '[email protected]'. Location: /:xxx[1]/:yyy[1]/*:Email[1]
The email field is defined in the schema as:
<xsd:simpleType name="EMailType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</xsd:restriction>
</xsd:simpleType>
Every email address that matches the regexp is considered valid except for something with underscores in it ([email protected]
is OK, [email protected]
is OK, but [email protected]
is not).
If I remove the underscore the XML is validated.
I've tested my regexp (which is the one you can find on MSDN for validating emails) with various tools and they all say it's valid. But not SQL Server.
Why does it not validate underscores? Is there something special I must do in SQL Server?
Upvotes: 5
Views: 4274
Reputation: 138960
Found a link about the issue with a workaround. http://www.agilior.pt/blogs/rodrigo.guerreiro/archive/2008/11/14/5965.aspx
Apparently \w
should include the underscore and does so except when it comes to handling XSD schemas. So this is not a specific SQL Server problem. I have the exact same behavior when validating an XML using XMLSpy.
Upvotes: 3