Jump to content

Recommended Posts

Hello,  I would like to limit a form email field to only send to two domains. The below code works great for one domain (domain1), but what if I also want to allow users to send to (domain2) as well? Thanks for looking!

 

if(empty($var)) {

//do nothing

} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+domain1.edu", $var)) {

  die ("<p>Error - please go back and enter a valid domain1 email address. Form does not allow EPHI sent outside of domain1.</p>");

}

Yeah, I would agree with Nightslyr, using a complex regular expression wouldn't be necessary for a definite amount of domains allowed. You should just use a wild card before the domain, or check to see if the domain even exists in the string.

I notice you're using ereg where I normally use preg, so perhaps the rules are different.

 

But you have domain.edu in your regexp.  That dot does not match a dot, it matches anything.  What you want is:

domain[.]edu or domain\.edu

 

Also, if you want multiple domains, try changing +domain1.edu to:

+(domain1)|(domain2)[.]edu

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.