Email validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
duffy
Forum Newbie
Posts: 19
Joined: Wed Aug 08, 2007 4:20 pm

Email validation

Post by duffy »

hey guys..

im lookin for help creating a code that has a result somewhat like this.
with all the validations, and the auto email validation sender, and the security code
and a box to insert the TOS (terms of service)



http://forums.d2jsp.org/index.php?act=Reg&CODE=00
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Email validation

Post by Benjamin »

duffy wrote:im lookin for help creating a code that has a result somewhat like this.
What part are you stuck on?
duffy
Forum Newbie
Posts: 19
Joined: Wed Aug 08, 2007 4:20 pm

Post by duffy »

everything.

i can create the boxes n stuff..

i have NO CLUE how to do the auto email validation
or how to verify 1 password with the other
or how to make the TOS box
or the security code.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Might want to search for some tutorials.
duffy
Forum Newbie
Posts: 19
Joined: Wed Aug 08, 2007 4:20 pm

Post by duffy »

k ill check it out.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

My email validation:

Code: Select all

/**
     *@param $Email is the email address you wish to validate
     *@return $result[0] will either be true or false. True
     *    meaning the email is valid - False meaning the email
     *    meaning the email is invalid.
     *@return $result[1] is a brief message explaining the result.
     */
    function VerifyEmail ($Email)
    {

        $result = array();

        #Use a regular expression to make sure the $Email string is in proper format
        #<username>@<domain>.<suffix> || <username>@<subnet>.<domain>.<suffix> 
        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
            $result[0] = false;
            $result[1] = "$email is not properly formatted.";
            return $result;
        } 


        list ($Username, $Domain) = split ("@", $Email);

        #Verify the MX record.
        if (getmxrr($Domain, $MXHost)) {
            $result[0] = true;
            $result[1] = "$email appears to be valid.";
            return $result;
        } else {
            #Establish a connection to the server.
            if (@fsockopen($Domain, 25, $errno, $errstr, 30)) {
                $result[0] = true;
                $result[1] = "$email appears to be valid.";
                return $result;
            } else  {
                $result[0] = false;
                $result[1] = "Cannot connect to the server.";
                return $result;
            }
        }
    } //End VerifyEmail
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

SidewinderX's email validation is somewhat limiting as the variety allowed in email addresses is quite substantial.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If you're looking for an application to do this, try hotscripts.com, or searching google for php email validation and sending scripts.

If you're looking to do it yourself. Go for it! And we can all help you when you get to a specific problem.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

feyd wrote:the variety allowed in email addresses is quite substantial
Yeah, I've had to fix up my email regex multiple times after seeing the valid emails that users have tried to sign up with. There's a lot more allowed than I had expected.
User avatar
Technocrat
Forum Contributor
Posts: 127
Joined: Thu Oct 20, 2005 7:01 pm

Post by Technocrat »

Code: Select all

define('REGEXP_TLD', '/(\.AC|\.AD|\.AE|\.AERO|\.AF|\.AG|\.AI|\.AL|\.AM|\.AN|\.AO|\.AQ|\.AR|\.ARPA|'. '\.AS|\.AT|\.AU|\.AW|\.AX|\.AZ|\.BA|\.BB|\.BD|\.BE|\.BF|\.BG|\.BH|\.BI|\.BIZ|\.BJ|\.BM|\.BN|\.BO|\.BR|\.BS|\.BT|'. '\.BV|\.BW|\.BY|\.BZ|\.CA|\.CAT|\.CC|\.CD|\.CF|\.CG|\.CH|\.CI|\.CK|\.CL|\.CM|\.CN|\.CO|\.COM|\.COOP|\.CR|\.CU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Y|\.UZ|'. '\.VA|\.VC|\.VE|\.VG|\.VI|\.VN|\.VU|\.WF|\.WS|\.YE|\.YT|\.YU|\.ZA|\.ZM|\.ZW)/i');
//Email defines from http://www.iamcal.com/publish/articles/php/parsing_email/
define('REGEXP_EMAIL_QTEXT', '[^\\x0d\\x22\\x5c\\x80-\\xff]');
define('REGEXP_EMAIL_DTEXT', '[^\\x0d\\x5b-\\x5d\\x80-\\xff]');
define('REGEXP_EMAIL_ATOM', '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+');
define('REGEXP_EMAIL_QUOTED_PAIR', '\\x5c[\\x00-\\x7f]');
define('REGEXP_EMAIL_DOMAIN_LITERAL', "\\x5b(".REGEXP_EMAIL_DTEXT."|".REGEXP_EMAIL_QUOTED_PAIR.")*\\x5d");
define('REGEXP_EMAIL_QUOTED_STRING',  "\\x22(".REGEXP_EMAIL_QTEXT."|".REGEXP_EMAIL_QUOTED_PAIR.")*\\x22");
define('REGEXP_EMAIL_SUBDOMAIN', "(".REGEXP_EMAIL_ATOM."|".REGEXP_EMAIL_DOMAIN_LITERAL.")");
define('REGEXP_EMAIL_WORD', "(".REGEXP_EMAIL_ATOM."|".REGEXP_EMAIL_QUOTED_STRING.")");
define('REGEXP_EMAIL_DOMAIN', REGEXP_EMAIL_SUBDOMAIN."(\\x2e".REGEXP_EMAIL_SUBDOMAIN.")*");
define('REGEXP_EMAIL_LOCAL_PART', REGEXP_EMAIL_WORD."(\\x2e".REGEXP_EMAIL_WORD.")*");
define('REGEXP_EMAIL', "!^".REGEXP_EMAIL_LOCAL_PART."\\x40".REGEXP_EMAIL_DOMAIN."$!");

function validEmail($data) {
    //Test to make sure there is a valid domain
    if (!preg_match(REGEXP_TLD, $data)) return false;
    //Test for @ and if the structure is correct
    return (preg_match('/.*@.*\..*/', $data) && preg_match(REGEXP_EMAIL, $data));
}
Post Reply