Regular Expression only allow alphanumeric plus other specific characters

With a PHP function I'm trying to create a RegEx string for preg_replace that will only allow alphanumeric characters plus ! @ # $ % & . ,

The PHP function is

 function clean($var) {
    $regEx="REGEXSTRING";   
    $var = preg_replace($regEx, "", $var);
    return str_replace(array("&", "'"),
    array("&", "'"), $var);
}

What would the string be to match what I'm looking for.

:: EDIT :: As I was typing this I figured out what would work for me. Not sure if it is the best solution but it works. But I figured I'd post it here as a solution for other beginners.

The string I used is...

$regEx="/[^a-zA-Z0-9 !@#$%&.,]/";

Hope it helps someone.

Answers


 function clean($var) {
    $regEx="/[^a-zA-Z0-9 !@#$%&.,]/"; 
    $var = preg_replace($regEx, "", $var);
    return str_replace(array("&", "'"),
    array("&", "'"), $var);
}

Need Your Help

Dynamically populate two dropdown menus

php javascript mysql dynamic drop-down-menu

I'm not (as I am certain you'll notice below) a programmer or coder. I write network documentation manuals.

Moving a ball randomly

iphone cocoa-touch uikit ios4

I am trying to move a ball across the screen with random coordinates . but my object moves just around x axis ! here is my code :

Developing on android-based device via wireless

android eclipse adb

One known way to develop your android application directly onto the device is using the usb connector and install the driver using eclipse. As such, is there a known way to do this wireless?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.