Page 1 of 1

showing warning for the use of / in perg_match

Posted: Fri Aug 13, 2010 6:38 am
by raj86
hello friends
m validating one input field in php. for that i m using perg_match function .

Code: Select all

preg_match('/[^a-zA-Z/., ]/', $vendor)
but this code is showing the below message
"Warning: preg_match() [function.preg-match]: Unknown modifier ',' in C:\wamp\www\inventory\desktops\update.php on line 158"

can anyone tell me how to use / symbol , so that it won`t give that warning

Re: showing warning for the use of / in perg_match

Posted: Fri Aug 13, 2010 7:28 am
by shawngoldw
It's giving you an error because the first letter you use is expected to be the last also. Since you start with a slash it expects the last letter to be a slash, so when you use a slash it is ending the regex. To fix it you need to do one of the following:

escape the slash:

Code: Select all

/[^a-zA-Z\/., ]/
or enclose the regex with a different character

Code: Select all

![^a-zA-Z/., ]!

Shawn