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
ZURINETAsked:
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 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 BormansInformation ArchitectCommented:
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
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.

 
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 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
0
 
Geert BormansInformation ArchitectCommented:
yep, I checked
http://www.ietf.org/rfc/rfc0822.txt?number=822
drill down the sequence
local-part > word > atom
0
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.