Hey guys,

I'm writing an autoresponder script.

How would I check to make sure someone typed in an email?

Since sometimes, some people just type in something random like 'shalhdash', how would I check that it's a legitmate email so the database doesn't record nonsense?

Would I check the string to make sure there's an @ in it? Or what would the best way to do this be?

Advice much appreciated.

    This was code I used

    if ($legal === "no" || empty($email) || $row_count > 0  ||  !ereg("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email))
    
      lilRachie wrote:

      This was code I used

      Apart from the fact that ereg() is deprecated in favour of preg_match(), that expression allows ".@.on" as an address and is also obsoleted by the recent decision to open up the TLD namespace.

        Weedpacket;10899922 wrote:

        ...as an address and is also obsoleted by the recent decision to open up the TLD namespace.

        Interesting.. seems like web developers are going to have to start adapting these changes, otherwise they risk locking out potentially valuable addresses..
        I was never a fan of ultra strict email regex validations to be honest.

        I prefer using filter_var() in conjunction with FILTER_SANITIZE_EMAIL and FILTER_VALIDATE_EMAIL, as it is more flexible, more forgiving, yet not a complete push-over for extremely invalid entries...

          nrg_alpha wrote:

          seems like web developers are going to have to start adapting these changes,

          They shouldn't have been so overly-restrictive in the first place. One of the principles of Internet protocol design is Postel's Law: "Be conservative in what you do; be liberal in what you accept from others"; also paraphrased as "be strict in what you generate, but forgiving in what you accept".

            Weedpacket;10899944 wrote:

            They shouldn't have been so overly-restrictive in the first place. One of the principles of Internet protocol design is Postel's Law: "Be conservative in what you do; be liberal in what you accept from others"; also paraphrased as "be strict in what you generate, but forgiving in what you accept".

            Oh I agree completely.. Just that I see many people coming into PHP forums and asking for precision regex email validation patterns...and sooner or later, someone is going try to send them an email via their site, and (while the sender's email address is perfectly correct and valid), will be denied in the face of ultra strict validation that didn't take such addresses into aco****).

            I must admit, I was initially tempted to go this route when constructing my contact page, but then realized it's best to have some flexible allowance and know that odds are good that they'll get through. So I no longer concerned myself with such tight-fisted approaches.

              9 days later
              Write a Reply...