note 34133 added to function.ereg

From: Date: Wed, 16 Jul 2003 21:06:55 +0000
Subject: note 34133 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-52229@lists.php.net to get a copy of this message
I found this to be the most efficient way of validating email addresses. I have scoured the internet looking for code and found some and made it a little simpler and it has 0 false positives. //@Author: Chris Williams //@Date: 7/16/03 //@Description: This function takes a scalar value as an argument then // it validates it with a reg exp then sees if the domain exists //@Usage: if(checkEmail($var))... ; function checkEmail($Email) { //Do the basic Reg Exp Matching for simple validation if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $Email)) { return FALSE; } //split the Email Up for Server validation list($Username, $Domain) = split("@",$Email); //If you get an mx record then this is a valid email domain if(getmxrr($Domain, $MXHost)) { return TRUE; } else { //else use the domain given to try and connect on port 25 //if you can connect then it's a valid domain and that's good enough if(fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } } } ---- Manual Page -- http://www.php.net/manual/en/function.ereg.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34133 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34133&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34133&report=yes

« previous php.notes (#52229) next »