JamieP Posted March 24, 2006 Share Posted March 24, 2006 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. Link to comment https://forums.phpfreaks.com/topic/5687-seeing-if-a-string-contains-an-email-address/ Share on other sites More sharing options...
redbullmarky Posted March 24, 2006 Share Posted March 24, 2006 [!--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] Link to comment https://forums.phpfreaks.com/topic/5687-seeing-if-a-string-contains-an-email-address/#findComment-20285 Share on other sites More sharing options...
JamieP Posted March 24, 2006 Author Share Posted March 24, 2006 Thanks redbullmarky, that worked =D Link to comment https://forums.phpfreaks.com/topic/5687-seeing-if-a-string-contains-an-email-address/#findComment-20385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.