• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Public Comment field - form validation regex help

Regex is admittedly one of my lacking areas. I am trying to create a validation rule for a "comment" field on a public form that only accepts:
1) Alphanumeric characters
2) Basic punctuation/symbols which only include .,?!#$%*()-+=;: and single and double quotes
3) Carriage Returns

I believe it is safer to not allow <> and &

Here is what I have put together from some examples on the net and my own. I've been testing it and it seems to work, but if there is anything I am missing or improvements I would sure appreciate any pointers.
return (preg_match("/[^\w\s\;\.\-\,\%\$\!\?\'\"\:\*\(\)\+\=\#]/iD", $str)) ? FALSE : TRUE;

Thank you!

Edit: the code highlighter doesn't seem to like it and Zend Studio complains about it, but it still seems to work.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.