SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm writing a "Recommend This Site" or "Tell-a-Friend" script, and I'm working on the part where the email addresses are checked for validity. I'm using ereg() to do it, but I want to make sure I'm including only the characters that are legal in an email address, but not leave anything out. I've looked at other scripts that perform a similar function as mine, but their use of ereg() allows dollar signs, commas, percent symbols, and a bunch of other characters I'm fairly certain are not valid in an email address.

    Here's what I have so far...
    Before the @: A throught Z (upper and lowercase), 0 (zero) through 9, and underscore (_). I don't think a hyphen (-) is allowed before the @, is it?
    After the @, before the TLD: A-Z, a-z, 0-9, -, and a period to accommodate subdomains and co.uk, etc.
    The top level domain is only allowed to be a-z, upper and lowercase.

    Did I miss anything or get any erronious information?
    Ed Rands

  2. #2
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hyphen and period ("-", ".") are allow in some email providers, as I have a couple of people in my address book that uses those symbols.

  3. #3
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the function I use:
    PHP Code:
    function check_email($email)
    {
        
    // returns true if $email is valid, false otherwise
        
    if (!$email)
            return 
    false;    // Fail if nothing supplied in argument
        
    if (!ereg("^.+@.+\\..+$"$email))
            return 
    false;     // Fail if ereg fails
        
    return true;    // If we get this far then it's fine

    The regular expression looks for something@something.something - it works fine, but it can be fooled by @@... for example.

  4. #4
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've used this:
    PHP Code:
    if ( eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z].)+[a-z]{2}[mtgvu]?$"$ReplyToAddress) )
    {
       
    // email is ok

    Check out http://www.sitepointforums.com/showt...threadid=21061 for more on that..

  5. #5
    SitePoint Evangelist thewitt's Avatar
    Join Date
    Apr 2001
    Posts
    468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd be well advised to spend some time in the RFCs at http://www.faqs.org to find out what's really legal or not in an email address.

    I think the answer will surprise you, as there are really very few illegal address characters when you look at how poor mans routing works. Back in the olden days of the Internet, it was not uncommon to have to specify the path and carrier you wanted the mail to take to get it delivered. This mechanism still works today, but few and far between are the people who can still route their mail themselves .

    -t


Bookmarks

Posting Permissions

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