← Prev in month
← Prev in thread
Next in thread →
Next in month →
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" <[email protected]>. 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.
------------------------------------------------------------------------------
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" <[email protected]>. 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*)*<(([a-zA-Z0-9!#$%&'\*\+/=\?\^`\{\}\|~\._-])|(".+")|(\\.))+@([a-zA-Z0-9-])+(([a-zA-Z0-9-])*\.([a-zA-Z0-9-])+)+>)|((([a-zA-Z0-9!#$%&'\*\+/=\?\^`\{\}\|~\._-])|(".+")|(\\.))+@([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.\\[email protected]>
"Test Person" <$A12345@example.com>
Abc\@def@example.com
"Fred Bloggs"@example.com
!def!xyz%abc@example.com
Random <customer/department=[email protected]>
------------------------------------------------------------------------------
Many thanks for any input,
Ben Azan
<?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*)*<(([a-zA-Z0-9!#$%&'\*\+/=\?\^`\{\}\|~\._-])|(".+")|(\\.))+@([a-zA-Z0-9-])+(([a-zA-Z0-9-])*\.([a-zA-Z0-9-])+)+>)|((([a-zA-Z0-9!#$%&'\*\+/=\?\^`\{\}\|~\._-])|(".+")|(\\.))+@([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.\\[email protected]>
"Test Person" <$A12345@example.com>
Abc\@def@example.com
"Fred Bloggs"@example.com
!def!xyz%abc@example.com
Random <customer/department=[email protected]>
------------------------------------------------------------------------------
Many thanks for any input,
Ben Azan
← Prev in month
← Prev in thread
Next in thread →
Next in month →