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

Who is Participating?
Geert BormansConnect With a Mentor Information ArchitectCommented:
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
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>

Open in new window

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
00 41 079 515 37 44
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


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

Open in new window

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

> but it will allow unvalid addresses such as
That user does not seem to currently exist on, but there is nothing inherently unvalid about that address.  You wouldn't want to have to change your regular expression every time added or removed a user.
Geert BormansInformation ArchitectCommented:
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
Geert BormansInformation ArchitectCommented:
yep, I checked
drill down the sequence
local-part > word > atom
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.