Jump to content

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 (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!

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.