Page 1 of 1
Email validation
Posted: Mon Aug 13, 2007 7:41 pm
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
Re: Email validation
Posted: Mon Aug 13, 2007 8:00 pm
by Benjamin
duffy wrote:im lookin for help creating a code that has a result somewhat like this.
What part are you stuck on?
Posted: Mon Aug 13, 2007 8:03 pm
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.
Posted: Mon Aug 13, 2007 8:06 pm
by Benjamin
Might want to search for some tutorials.
Posted: Mon Aug 13, 2007 8:21 pm
by duffy
k ill check it out.
Posted: Mon Aug 13, 2007 11:11 pm
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
Posted: Tue Aug 14, 2007 9:13 am
by feyd
SidewinderX's email validation is somewhat limiting as the variety allowed in email addresses is quite substantial.
Posted: Tue Aug 14, 2007 9:21 am
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.
Posted: Tue Aug 14, 2007 9:27 am
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.
Posted: Tue Aug 14, 2007 11:36 am
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|'. '\.CV|\.CX|\.CY|\.CZ|\.DE|\.DJ|\.DK|\.DM|\.DO|\.DZ|\.EC|\.EDU|\.EE|\.EG|\.ER|\.ES|\.ET|\.EU|\.FI|\.FJ|\.FK|\.FM|'. '\.FO|\.FR|\.GA|\.GB|\.GD|\.GE|\.GF|\.GG|\.GH|\.GI|\.GL|\.GM|\.GN|\.GOV|\.GP|\.GQ|\.GR|\.GS|\.GT|\.GU|\.GW|\.GY|'. '\.HK|\.HM|\.HN|\.HR|\.HT|\.HU|\.ID|\.IE|\.IL|\.IM|\.IN|\.INFO|\.INT|\.IO|\.IQ|\.IR|\.IS|\.IT|\.JE|\.JM|\.JO|\.JOBS|'. '\.JP|\.KE|\.KG|\.KH|\.KI|\.KM|\.KN|\.KR|\.KW|\.KY|\.KZ|\.LA|\.LB|\.LC|\.LI|\.LK|\.LR|\.LS|\.LT|\.LU|\.LV|\.LY|\.MA|'. '\.MC|\.MD|\.MG|\.MH|\.MIL|\.MK|\.ML|\.MM|\.MN|\.MO|\.MOBI|\.MP|\.MQ|\.MR|\.MS|\.MT|\.MU|\.MUSEUM|\.MV|'. '\.MW|\.MX|\.MY|\.MZ|\.NA|\.NAME|\.NC|\.NE|\.NET|\.NF|\.NG|\.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));
}