Ask Experts Questions for FREE Help !
Ask
    Animal's Avatar
    Animal Posts: 1, Reputation: 1
    New Member
     
    #1

    Apr 24, 2003, 06:25 PM
    Properly formatted emails
    Hello,

    What determines a valid (or invalid) email address? I'm writing a script which can determine whether the formatting is correct or not. For example, you need an "@" sign, a ".", etc. You can't have spaces or backslashes in an email, etc.

    Does someone have a complete list of rules?

    Thanks,
    Steve
    cyrus's Avatar
    cyrus Posts: 65, Reputation: 1
    Junior Member
     
    #2

    Apr 24, 2003, 06:43 PM
    Properly formatted emails
    Most java scripts that are written to check for a valid e-mail only check for the "@" and that it contains a "." that's it ;)
    zylstra's Avatar
    zylstra Posts: n/a, Reputation:
    Guest
     
    #3

    May 13, 2003, 05:47 PM
    Properly formatted emails
    From the CGI/Perl CookBook:

    Code:
    sub email_check {
        local($email) = $_[0];
    
        # Check that the email address doesn't have 2 @ signs, a .., a @., a 
        # .@ or begin or end with a .
    
        if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/ || 
    
            # Allow anything before the @, but only letters numbers, dashes and 
            # periods after it.  Also check to make sure the address ends in 2 or 
            # three letters after a period and allow for it to be enclosed in [] 
            # such as [164.104.50.1]
        
            ($email !~ /^.+\@localhost$/ && 
             $email !~ /^.+\@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)) {
            return(0);
        }
    
        # If it passed the above test, it is valid.
        
        else {
            return(1);
        }
    }
    Here's some more Perl code:

    Code:
    $a = "john\@example.com"; 
    print &CheckEmailAddress($a); 
    sub CheckEmailAddress() { 
    # This regexp validates the format of an email address. It returns the cleaned 
    # version of the email address, or blank if the address was not valid. 
    # 
    # An email address must be of the form: 
    # 1) (trim any spaces or tabs or linefeeds or carriage returns) 
    # 2) (possibly one quotation mark) 
    # 3) (one or more characters for username, excepting a quotation mark) 
    # 4) (possibly one quotation mark) 
    # 5) @ 
    # 6) (one or more characters for hostname(s), excepting [ <>\t]) 
    # 7) . 
    # 8) (two or more characters for top-level-domain, excepting [ <>\t]) 
    # 9) (trim any spaces or tabs or linefeeds or carriage returns) 
    # 
    # 1 2 3 4 56 7 8 9 
    # .............'''.......'''.'''''''''..''''''''''''''''''............. 
        $_[0] =~ /[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[ |\t|\r|\n]*/; 
        return $1; 
    }
    Or, if you're using Perl you can use the module Mail::RFC822::Address.

    Or, if you like reading specs, it's supposed to be in RFC822, http://www.faqs.org/rfcs/rfc822.html, but I couldn't find it.

    -Z

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Does anyone else get emails like this? [ 12 Answers ]

I was just wondering if anyone else ever gets emails like this.. I find them annoying and somehow wrong. I am sure it's a scam. I almost wonder if some of it is a terriorist plot, due to the timing and the way it's handled. I would love some feedback as far as what you think and if possible who to...

Emails [ 1 Answers ]

WHEN I OPEN AN EMAIL UP SOME OF THEM Won't PLAY IT LOOKS LIKE ITS GOING TO START PLAYING BUT THEN IT SAYS THIS... Windows Media Player cannot connect to the server. The server name might not be correct, the server might not be available, or your proxy settings might not be correct. SOMEONE...

Formatted C and now no signal! [ 3 Answers ]

Hi The problem probably begins with the fact that I am no PC guru but I already know that (and you will to after reading this) so here's what happened... I wanted to reinstall Windows XP so stupidly I thought why not format my C - that has the OS on it - so that all the junk will be cleaned...

Installing win95 on a re-formatted HD [ 3 Answers ]

Ok, so here's the problem: I just got an HD from a friend, it's an OLD one and I just completely reformatted it. I want to install Windows 95 on it, I have the disk and everything, but I can't install because it says it can't install under NT (I have XP). I want to install 95 on the HD I just got,...

HTML emails [ 1 Answers ]

Hello, can anyone help me with some HTML (CGI-SCRIPTS) programming. I am trying to send an automatic email to everyone who submits a feedback form to me on my site. Problem is I want to send Japanese characters, which can only be done via an HTML email. At the moment my comand is: <form...


View more questions Search