www.webdeveloper.com
Results 1 to 5 of 5

Thread: I need help with apostrophe in email validation

  1. #1
    Join Date
    Jan 2006
    Location
    St Louis MO USA
    Posts
    35

    I need help with apostrophe in email validation

    I am using this script for email validation and it worked well until...

    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form1.PriEmail.value))

    ...apostrophes were introduced. If there is an apostrophe in the address the test fails the address. How do I fix it?

    Thanks

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    There is many regular expressions (like this according to the RFC 822 grammar for perl) to test email addresses...

    For practical use, see this page which give good reasons to take this kind of validation with precautions and to write, in case of failure, only a warning with something like : your email address seems erroneous !

    For example, your test will fails with the top level domain museum or travel which are 6 letters (See this page for the IANA list which could be used on the server).

    The best test for validation consists to send an email for confirmation !

    NB : Since it's easy to add apostrophes with something like this : if (/^\w+([\.-']?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form1.PriEmail.value))
    Last edited by 007Julien; 08-29-2012 at 09:13 AM. Reason: complément

  3. #3
    Join Date
    Jan 2006
    Location
    St Louis MO USA
    Posts
    35

    Thanks

    The script you inserted did the trick.

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Yes but this form could be better
    Code:
     if (/^\w+([\.'-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form1.PriEmail.value))
    To display the hyphen at the end of the sub-pattern (since it has to be escape with a \).

  5. #5
    Join Date
    Jan 2006
    Location
    St Louis MO USA
    Posts
    35

    Yes that is better

    I just began testing the first version and the second version works better.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles