Page 1 of 1

Checking email

Posted: Thu Aug 05, 2004 12:20 am
by dwfait
Hi. How would i check to see if an email was in the right format?

for example, check to see if a string was *@*.*
where * could be anything.

Posted: Thu Aug 05, 2004 12:31 am
by feyd
search the forums.. we've talked about this ad nauseum.

Posted: Thu Aug 05, 2004 1:24 am
by LiquidPro
I believe you have to use preg_match...

Try this...

Code: Select all

function check_email($email) {
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) {
      return true;
   } else {
      return false;
   }
}

Posted: Thu Aug 05, 2004 1:37 am
by feyd
Hate to nitpick but, last I checked, a space wasn't allowed in a domain name, and dots could appear anywhere leading up to the @.. missing underscores in domain name too. Might potentially need allowance for ip addresses as the domain too.

Posted: Thu Aug 05, 2004 1:41 am
by LiquidPro
That's true, I'll have to fix that. And don't worry about nitpicking... programming has to be nitpicked or it won't work, haha.

What do you think about that one? It doesn't have ip address support though.