Fortunately, there are libraries of well defined regular expressions from which to start with, so it isn't so intimidating.
http://www.expertsrt.net/m
Is an excellent place to start.
Main Topics
Browse All TopicsHow can I check if a string contains symbols or weird characters like !@#$%^%^&&*(())-+=?><,.'"}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Fortunately, there are libraries of well defined regular expressions from which to start with, so it isn't so intimidating.
http://www.expertsrt.net/m
Is an excellent place to start.
Business Accounts
Answer for Membership
by: HackneyCabPosted on 2007-08-12 at 04:16:51ID: 19678784
A better way to do things is to check that a string only contains the characters that are allowed. This is known as using a whitelist. Checking for illegal characters is known as using a blacklist. A whitelist is much easier to maintain than a blacklist.
Using regular expressions is a quick and easy way to check for character classes, so take a look at preg_match in the PHP documentation.
For instance, if your string only permitted letters, digits and standard spaces, you could use this to check that the string was valid:
$valid = preg_match('/^[a-z0-9 ]+$/', $string);
This does not allow an empty string, but if you change the + to a * the empty string will be permitted. If the string is valid, then $valid will equal true.
Regular expressions are not easy to grasp at first, but they are very powerful for string validation and manipulation.