Jump to content

[SOLVED] Help with validating form email addresses


Sportbob

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

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.