pourmeanother Posted November 5, 2008 Share Posted November 5, 2008 PHP4 Let's say I want to verify an email a user enters with their registration to see if it's from a specific site. Example: let's say I only want users to register using an AOL email address (user@aol.com), how would I check for the '@aol.com' ending? <?php //...continued from code above.... if(eregi("email", $field) { if(!ereg("^.+@.+\\..+$", $value)) { $message[]="$value is not a valid email address"; } elseif(______________) { $message[]="$value is not an AOL email address"; } } ?> Please fill in the blank. Also, let me know if everything checks out for PHP4; I've had to convert after using PHP5. THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/131467-email-verification-with-ereg/ Share on other sites More sharing options...
Adam Posted November 5, 2008 Share Posted November 5, 2008 Quite a few ways to do it I dare say, and probs one being a regular expression but I'm not very good with them.. Though I do have a few ideas: $emailArr = explode('@', $email); if ($emailArr[1] == 'aol.com') { // register user } OR: $pos = strpos($email, '@'); $domain = substr($email, $pos); if ($domain == '@aol.com') { // register user } You should be able to condense that a bit to: $domain = substr($email, strpos($email, '@')); Provided you've validated it as a valid email, because it returns false if there' no occurence, which obviouslly could cause an error in substr().. Adam Quote Link to comment https://forums.phpfreaks.com/topic/131467-email-verification-with-ereg/#findComment-682793 Share on other sites More sharing options...
pourmeanother Posted November 5, 2008 Author Share Posted November 5, 2008 Just to further check, implement like this given the code in the O.P.? <?php //....continued..... elseif( substr($value, strpos($value, '@')) !== '@aol.com' ) { $message[]="$value is not an AOL email address"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131467-email-verification-with-ereg/#findComment-683209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.