Jump to content

Email verification with ereg


pourmeanother

Recommended Posts

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 ([email protected]), 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!

Link to comment
https://forums.phpfreaks.com/topic/131467-email-verification-with-ereg/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.