I'm trying to allow apostrophe's in a particular form input for this social site I've been working on forever. I'm using regular expressions to test most of my inputs for illegal characters, but I want to allow ' in this exception. Is there a way to use [[:punct:]], but with the apostrophe as an exception, or do you have to list everything and just leave out apostrophe. Thanks again for all the help.
You could just use an apostrophe. For instance, if you want to allow letters and apostrophes but nothing else, and the value cannot start or end with an apostrophe:
if(preg_match('/^[a-z]+(\'[a-z]+)?$/i', $value)) { // OK } else { // invalid }
Awsome. Thank you very much. That should work perfectly. I need to get better at reg. ex. syntax. One of these days I'm going to spend some time studying.
PS: If you need to allow more than one apostrophe, change the )? to )* in the pattern.
Thanks, that works well. Looks like one problem I was having was a lot of magic slashes coming out of nowhere. So, of course I had to stripslashes() from a lot of my strings first.