We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


If Statement Question.

FirstBorn asked
Medium Priority
Last Modified: 2008-02-20

I am looking for the Correct IF Statement to validate the domain.tld part of an email.

Here is what I have:
            // check if email is a valid address in this format username@domain.com
            if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>";
Problem is, I need to check the domain.tld part of it so that it checks for a SPECIFIC domain.tld such as whatever@mysite.com instead of whatever@anydomain.tld.
(I don't need for it to check the 'whatever' part, just the '@anydomain.tld' part.)


Watch Question

you could do this much easier by just getting the substring of the email after the @ symbol and checking it since it will always be static.

if(substr($email_input,strpos($email_input,'@')+1)!=="mysite.com") $error_msg.= "You're not from the right site!<br/>";

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Hi quad,

I changed it to:
if(substr($email_input,strpos($email_input,'@')+1)=="mysite.com") $error_msg.= "Busted! Now GO AWAY!!!<br/>";
and it worked...
Had a few errors at first, but it was 'cause I put it in the wrong spot somehow...

Thank You VERY Much for the Quick Response and for Your Help!


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.