Regular Expression to Validate Email Addresses

Posted on 2009-04-26
Last Modified: 2012-05-06
I am looking for regular expression . to use in a schema to validate valid e-mail addresses

Thanks in Advance

Question by:ZURINET
    LVL 60

    Accepted Solution

    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


    Author Comment

    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


    LVL 60

    Expert Comment

    by:Geert Bormans
    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

    LVL 84

    Expert Comment

    > 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.
    LVL 60

    Expert Comment

    by:Geert Bormans
    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
    LVL 60

    Expert Comment

    by:Geert Bormans
    yep, I checked
    drill down the sequence
    local-part > word > atom

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now