Welcome Guest, Not a member yet? Register   Sign In
Public Comment field - form validation regex help
#1

[eluser]CroNiX[/eluser]
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.
Code:
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.




Theme © iAndrew 2016 - Forum software by © MyBB