If Statement Question.

Posted on 2006-03-31
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
            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 instead of whatever@anydomain.tld.
(I don't need for it to check the 'whatever' part, just the '@anydomain.tld' part.)


Question by:FirstBorn
    LVL 6

    Accepted 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)!=="") $error_msg.= "You're not from the right site!<br/>";
    LVL 1

    Author Comment

    Hi quad,

    I changed it to:
    if(substr($email_input,strpos($email_input,'@')+1)=="") $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!



    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now