• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

If Statement Question.


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.)


1 Solution
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/>";
FirstBornAuthor Commented:
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!


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now