Friday, April 2, 2010

PHP function to check for invalid characters



function isValid($str) {
return !preg_match('/[^A-Za-z0-9.#\\-$]/', $str);
}




If you also want to include a space, then add \s
so in this example:


function isValid($str) {
return !preg_match('/[^A-Z\sa-z0-9.#\\-$]/', $str);
}