user4fun Posted August 19, 2007 Share Posted August 19, 2007 I use this to validate the sturcuture of the email if (!stristr($email,"@") OR !stristr($email,".")){$status= "NOTOK";//some more stuff} What other options are there to do more with validating an email address, any tutorials maybe? Link to comment Share on other sites More sharing options...
Matpatnik Posted August 19, 2007 Share Posted August 19, 2007 You can use regular expression, something like that if (!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" . "@" . "([a-z0-9]+([\.-][a-z0-9]+)*)+" . "\\.[a-z]{2,4}" . "$",$Email)) { // ...} Link to comment Share on other sites More sharing options...
boen_robot Posted August 19, 2007 Share Posted August 19, 2007 I'd suggest using filter like so: if (filter_var($email, FILTER_VALIDATE_EMAIL)) {$status= "NOTOK";//some more stuff} smaller, easier, maybe faster and probably more secure (as you're relying on a prewriten check specifically for that). Link to comment Share on other sites More sharing options...
Diegar Posted October 18, 2007 Share Posted October 18, 2007 I'd suggest using filter like so:if (filter_var($email, FILTER_VALIDATE_EMAIL)) {$status= "NOTOK";//some more stuff} smaller, easier, maybe faster and probably more secure (as you're relying on a prewriten check specifically for that). I was very happy to find this post, but found a problem with it. if (filter_var($email, FILTER_VALIDATE_EMAIL)) {$status= "NOTOK";//some more stuff} didn't work....So i changed it to... if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {$status= "NOTOK";//some more stuff} That seems to work... if i am wrong, please let me know Link to comment Share on other sites More sharing options...
Hooch Posted October 18, 2007 Share Posted October 18, 2007 Hi Diegar. Here is the code I found on the net, by a user named aslav function validateEmail ( $email ){ // Create the syntactical validation regular expression $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"; // Presume that the email is invalid $valid = 0; // Validate the syntax if (eregi($regexp, $email)) { list($username,$domaintld) = split("@",$email); if (getmxrr($domaintld,$mxrecords)) $valid = 1; } else { $valid = 0; } return $valid;} I did not code this myself, and do not take credit for it. But I have used it and it works perfect for me. I like it because it check to see if that domain is true. Hooch Link to comment Share on other sites More sharing options...
Synook Posted October 18, 2007 Share Posted October 18, 2007 That seems to work... if i am wrong, please let me knowDepends what is meant by NOTOK, if that means that the email address is bad, then you are right. Link to comment Share on other sites More sharing options...
jlhaslip Posted October 21, 2007 Share Posted October 21, 2007 from the php documentation for the getmxrr function: Note: This function should not be used for the purposes of address verification. Link to comment Share on other sites More sharing options...
Err Posted October 21, 2007 Share Posted October 21, 2007 I use the follow code, it has worked great for me so far. I forgot where I got it from, but you can do a quick google search and get some results: function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } Also, the best way to make sure that the e-mail address is valid is to send the user an e-mail message that he/she has to open and click a link to verify it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.