Jump to content

Seeing if a string contains an email address


JamieP

Recommended Posts

Hi, I want to see if a string contains an email address, I know how to see if it JUST contains an email address, but I don't want that, it's for a private messaging system, and we do not allow email addresses to be sent, so I need a way to check to see if the variable containing the text contains an email address.
[!--quoteo(post=357940:date=Mar 24 2006, 03:12 PM:name=JamieP)--][div class=\'quotetop\']QUOTE(JamieP @ Mar 24 2006, 03:12 PM) [snapback]357940[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi, I want to see if a string contains an email address, I know how to see if it JUST contains an email address, but I don't want that, it's for a private messaging system, and we do not allow email addresses to be sent, so I need a way to check to see if the variable containing the text contains an email address.
[/quote]

ok i'm sure there's a shorter pattern than this, but try:

[code]
$email = "this is a string with an email: [email protected] in it";

$result = preg_match("/[A-Za-z0-9][A-Za-z0-9\.\_]*[@][A-Za-z0-9\.]*[.]([A-Za-z]{2,3})[.]?([A-Za-z]{2})?/", $email);

if ($result)
   echo 'email found in string';
else
   echo 'no emails';
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.