[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Email Validation with Regular Expression

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

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@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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.