showing warning for the use of / in perg_match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raj86
Forum Commoner
Posts: 25
Joined: Tue Sep 29, 2009 12:28 am

showing warning for the use of / in perg_match

Post 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
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: showing warning for the use of / in perg_match

Post 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
Post Reply