Email validation
Moderator: General Moderators
Email validation
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
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
Re: Email validation
What part are you stuck on?duffy wrote:im lookin for help creating a code that has a result somewhat like this.
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
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 VerifyEmailIf 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.
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.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat J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.NI|\.NL|\.NO|\.NP|\.NR|\.NU|\.NZ|\.OM|\.ORG|\.PA|'. '\.PE|\.PF|\.PG|\.PH|\.PK|\.PL|\.PM|\.PN|\.PR|\.PRO|\.PS|\.PT|\.PW|\.PY|\.QA|\.RE|\.RO|\.RU|\.RW|\.SA|\.SB|\.SC|'. '\.SD|\.SE|\.SG|\.SH|\.SI|\.SJ|\.SK|\.SL|\.SM|\.SN|\.SO|\.SR|\.ST|\.SU|\.SV|\.SY|\.SZ|\.TC|\.TD|\.TEL|\.TF|\.TG|'. '\.TH|\.TJ|\.TK|\.TL|\.TM|\.TN|\.TO|\.TP|\.TR|\.TRAVEL|\.TT|\.TV|\.TW|\.TZ|\.UA|\.UG|\.UK|\.UM|\.US|\.UY|\.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));
}