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. 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: [email protected] "; if (preg_match('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/si', $var)) { die("Contains an email"); } ?> 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! 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.. 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
Archived
This topic is now archived and is closed to further replies.