Daniel
Daniel

Reputation:

php registration form - limit emails

i want to restrict certain emails to my website.

an example would be that i only want people with gmail accounts to register to my website.

{
     /* Check if valid email address */
     $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
             ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
             ."\.([a-z]{2,}){1}$";
     if(!eregi($regex,$subemail)){
        $form->setError($field, "* Email invalid");
     }
     $subemail = stripslashes($subemail);
  }

this is what i have so far to check if its a valid email.

Upvotes: 0

Views: 455

Answers (3)

AntonioCS
AntonioCS

Reputation: 8496

How about doing something like:

list(,$domain) = explode('@',$email);
if ($domain != 'gmail.com')
  echo 'not possible to register';
else 
  echo 'Will register';

If you want to validate the email use the filter functions

Upvotes: 0

grawity_u1686
grawity_u1686

Reputation: 16532

Don't use a single regex for checking the entire address. Use strrpos() split the address to local part and domain name, check them separately. Domain is easy to check, the local part is almost impossible (and you shouldn't even care about it).

Upvotes: 1

farzad
farzad

Reputation: 8855

I suggest you keep an array of regex patterns that you would like the email address to match against. then write a loop to iterate over the array and check the address. whenever a check failed, set some validation flag to false. after the loop, by checking the validation flag you can make sure that the email address is exactly what you want.

Upvotes: 0

Related Questions