[Home] [By Thread] [By Date] [Recent Entries]

  • From: "Benjamin Azan" <ben.azan@g...>
  • To: xml-dev@l...
  • Date: Thu, 28 Feb 2008 14:35:48 -0500

Hi dev-xml,

I have a question about e-mail validation with regular expressions.
I've seen a lot of regular expressions out there to validate RFC 2822
e-mail addresses. Seems like there are many variants but few for the XML
schema flavor of regex.

I've written on such expression and was wondering what people think of
it, if is satisfies the standard and whether people know of any better
email Regex for XML schema.

I'm also not sure if display names are allowed to have quotes around
them like: "Ben Azan" <ben.aza@g...>. Gmail does this, but I
can't seem to find it in the RFC 2822.

My goal was to support display-names as well as quoting and \ for
escaping characters in the local-part of the e-mail.

------------------------------------------------------------------------------
Here is the xsd code:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:e="http://rep.oio.dk/email"
targetNamespace="http://rep.oio.dk/email"
elementFormDefault="qualified" version="1.0">
       <xsd:element name="email" type="e:emailType"/>
       <xsd:simpleType name="emailType">
               <xsd:restriction base="xsd:string">
                       <xsd:pattern
value="((\S*\s*)*&lt;(([a-zA-Z0-9!#$%&amp;'\*\+/=\?\^`\{\}\|~\._-])|(&quot;.+&quot;)|(\\.))+@([a-zA-Z0-9-])+(([a-zA-Z0-9-])*\.([a-zA-Z0-9-])+)+&gt;)|((([a-zA-Z0-9!#$%&amp;'\*\+/=\?\^`\{\}\|~\._-])|(&quot;.+&quot;)|(\\.))+@([a-zA-Z0-9-])+(([a-zA-Z0-9-])*\.([a-zA-Z0-9-])+)+)"/>
               </xsd:restriction>
       </xsd:simpleType>
</xsd:schema>

------------------------------------------------------------------------------
This validates e-mail address like:

hello world    <Joe.\\Blow@e...>

"Test Person" <$A12345@http://example.com/>

Abc\@def@http://example.com/

"Fred Bloggs"@http://example.com/

!def!xyz%abc@http://example.com/

Random <customer/department=shipping@e...>

------------------------------------------------------------------------------
Many thanks for any input,

Ben Azan


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member