Hey all! I have a question that I just need a real solid answer to ;) Basically, I need a PHP script that checks values inputted by a form for special characters (only allows letters, numbers, and apostrophes). For form validation :D. I'm really not the best with regexes otherwise I would figure it out, but I've spent a lot of time searching this and haven't been able to find it. Please help!!! Thanks a ton!

EDIT:

Thanks to all who helped! How can I add blank characters (like if the field is left empty) to this regex:

#^[a-z\' -]+$#i

And the {}s that specify length. How could I go about that? Thanks!

+ means 1 or more
* means 0 or more

#^[a-z\' -]*$#i

The following needs exactly 4 of the specified characters

#^[a-z\' -]{4}$#i

Thank you very much! Now how can I make it so a blank value will pass the expression? Thanks again!

don't think that regex will return an empty value. It will return 1 or more spaces.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.