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. Quote Link to comment 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: hello@example.com 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] Quote Link to comment Share on other sites More sharing options...
JamieP Posted March 24, 2006 Author Share Posted March 24, 2006 Thanks redbullmarky, that worked =D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.