XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Email Validation with Regular Expression

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@gmail.com>. 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@example.com>

"Test Person" <$A12345@example.com>

Abc\@def@example.com

"Fred Bloggs"@example.com

!def!xyz%abc@example.com

Random <customer/department=shipping@example.com>

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

Ben Azan


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


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS