carole2 Posted July 26, 2006 Share Posted July 26, 2006 I would like a reg expression that can check for the existence of an email address in a string. This is to prevent users from entering an email address into a particular field. regardscarole Link to comment https://forums.phpfreaks.com/topic/15710-test-for-email-address-in-string/ Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 Prehaps this [url=http://www.phpfreaks.com/forums/index.php/topic,101005.0.html]thread[/url] might be able to help you out. Look at post number 3 by toplay. Link to comment https://forums.phpfreaks.com/topic/15710-test-for-email-address-in-string/#findComment-64137 Share on other sites More sharing options...
carole2 Posted July 26, 2006 Author Share Posted July 26, 2006 [quote author=wildteen88 link=topic=101948.msg403973#msg403973 date=1153930842]Prehaps this [url=http://www.phpfreaks.com/forums/index.php/topic,101005.0.html]thread[/url] might be able to help you out. Look at post number 3 by toplay.[/quote]Thanks that was helpful but i would like a reg expression that would allow all text except for an email address, if that is possible. Link to comment https://forums.phpfreaks.com/topic/15710-test-for-email-address-in-string/#findComment-64259 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 You do something like this:[code]<?php$text = "Hey my email adddy is [email protected] isnt it nice";if(preg_match("/([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})/i", $text)){ echo "Email adddy detected, We do not accept email addresses within strings!";}else{ echo "No email addy dectected";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/15710-test-for-email-address-in-string/#findComment-64276 Share on other sites More sharing options...
carole2 Posted July 26, 2006 Author Share Posted July 26, 2006 [quote author=wildteen88 link=topic=101948.msg404126#msg404126 date=1153940858]You do something like this:[code]<?php$text = "Hey my email adddy is [email protected] isnt it nice";if(preg_match("/([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})/i", $text)){ echo "Email adddy detected, We do not accept email addresses within strings!";}else{ echo "No email addy dectected";}?>[/code][/quote]Thanks..Yeah thats a possibility i thought of that already. .. I am using a form class that validates on the server side and the client side. On the client side javascript is created from the reg expression. So i was looking for just a reg expression that would not accept any text that contained an email address. Its not that important as i could validate it on the server side only with the above code. Thanks for your input... Link to comment https://forums.phpfreaks.com/topic/15710-test-for-email-address-in-string/#findComment-64293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.