View Full Version : why php preg_match for single quote doesn't work

07-31-2007, 11:53 PM
With the below PHP code, user can use enter all those characters in the comments form field.

if (!preg_match( "/^[-a-zA-Z0-9_\,\;\:\#\!\=\*\?\+\%\.\$\%\(\)\n\r]{0,600}$/" , $strComments))

However, I did want to give them the option of using a single quote so I added \' to the regexp and it doesn't work. That is, when user enters single quote in the comment form, it results in an error - like AS IF i had restricted them from using it.

if (!preg_match( "/^[-a-zA-Z0-9_\,\;\:\#\!\=\*\?\'\+\%\.\$\%\(\)\n\r]{0,600}$/" , $strComments))

Is this default behaviour or am I missing something?