Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing "&" in preg_match

Status
Not open for further replies.

webdev007

Programmer
Sep 9, 2005
168
I am not very much regex fluent
I can't make the following working 100% it only partially works:
if (!preg_match("/^[\(\)\/\'\"\,\.\-\&\ _a-zA-Z0-9\d]+$/",$biz_name) )

I need to allow for any letters, numbers, and some special characters in any order (this depicts a business name)
so far I can't get it workng when I want to allow for: &

thank you for your input.
 
This is my variation. It accepts ampersands in strings:

Code:
<?php

$names = array ('I. E. duPont neMours and Company, Inc.', 'Target', 'Proctor & Gamble', '21nation', 'b**ze');

print '<html><body><pre>';
foreach ($names as $name)
{
	print 'Name: ' . $name . ': ';
	if (preg_match ('/^[\w \(\)\/\'",.\&]+$/i', $name))
	{
		print 'good';
	}
	else
	{
		print 'bad';
	}
	
	print "\n";
}
print '</pre></body></html>';
?>



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thank you
I may understand how you built it
and going the other way around using preg_match(); instead of !preg_match(); makes sense

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top