• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Regular Expression to Validate Email Addresses

I am looking for regular expression . to use in a schema to validate valid e-mail addresses

Thanks in Advance

ZH
0
ZURINET
Asked:
ZURINET
  • 4
1 Solution
 
Geert BormansCommented:
mmh, I am not sure if you can cover the the full RFC spec in a regular expression

I think that this comes close
but it will allow unvalid addresses such as abc..@def.com
How strict do you want to be?
There is a trade off I am afraid. or you make sure that the pattern makes strings thta are too long unvalid, or you make sure that pattern is robust for avoiding trailing or leading "." or subsequent "." which all are also not allowed
I don't think you can have both in a single regex
<xs:simpleType name="email-type-base">
    <xs:restriction base="xs:string">
        <xs:pattern value="[a-zA-Z0-9!#$%&amp;'*+\-/=?\^_{|}~\.]{1,64}@[a-zA-Z0-9\-\.]{1,255}"></xs:pattern>
    </xs:restriction>
</xs:simpleType>

Open in new window

0
 
ZURINETAuthor Commented:
Hi Gertone

Thanks for your help..
I just need to do some experiment.. :-)

Your solutions it just okay..

Just one more comment.. please

How can I represent  international and national phone number

 + 41 079 515 37 44
or  
00 41 079 515 37 44
or
00- 41 - 079 - 515 - 37- 44
or 079 515 37 44

I need to filter only these number formats with regular expression

I need to be able to accept numbers 0 - 9 including + and - signs

Thanks





0
 
Geert BormansCommented:
This will do
<xs:simpleType name="tel-type-base">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9+\-\s]+"></xs:pattern>
    </xs:restriction>
</xs:simpleType>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ozoCommented:
> but it will allow unvalid addresses such as abc..@def.com
That user does not seem to currently exist on def.com, but there is nothing inherently unvalid about that address.  You wouldn't want to have to change your regular expression every time def.com added or removed a user.
0
 
Geert BormansCommented:
According to the email address RFC, a local part of an email address should not
- start with a dot
- end with a dot
- have two dots in a row
so that is inherently unvalid as far as I know
0
 
Geert BormansCommented:
yep, I checked
http://www.ietf.org/rfc/rfc0822.txt?number=822
drill down the sequence
local-part > word > atom
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now