andersj Posted July 16, 2008 Share Posted July 16, 2008 Hello, I've run into a problem where I've tried everything possible on something that really isn't so hard. On my form validation, I am checking if the posted string contains an email. If it does I want to throw up an error. It's coming from a textarea so there can be as much text before or after the email, it just needs to throw up that area, if one is in there. I've tried incorporating regular expressions with no avail. Your help would be much appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/114951-solved-check-if-string-contains-email/ Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 try this <?php $var = "this is my email: tester@testing.com "; if (preg_match('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/si', $var)) { die("Contains an email"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114951-solved-check-if-string-contains-email/#findComment-591210 Share on other sites More sharing options...
andersj Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks man, that did it! I really need to freshen up on my regular expressions, I almost had what you had! But thanks again, your a life saver! Quote Link to comment https://forums.phpfreaks.com/topic/114951-solved-check-if-string-contains-email/#findComment-591213 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 yeah regular expressions can be a pain but also fun.. but when you start you try to use them for everything lol.. Quote Link to comment https://forums.phpfreaks.com/topic/114951-solved-check-if-string-contains-email/#findComment-591215 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.